tree:
https://git.kernel.org/pub/scm/linux/kernel/git/chao/linux.git simple_copy
head: d6f32b90156624ae9dc06ef5873334a48e9b9806
commit: fcbd83ffa72af1eba12bcab1f34e0b956a563e02 [2/5] block: add simple copy support
config: xtensa-randconfig-m031-20210209 (attached as .config)
compiler: xtensa-linux-gcc (GCC) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp(a)intel.com>
Reported-by: Dan Carpenter <dan.carpenter(a)oracle.com>
smatch warnings:
block/blk-lib.c:221 blk_read_to_buf() error: uninitialized symbol 'bio'.
block/blk-lib.c:352 blkdev_issue_copy() warn: ignoring unreachable code.
vim +/bio +221 block/blk-lib.c
fcbd83ffa72af1e SelvaKumar S 2021-02-08 180 int blk_read_to_buf(struct block_device
*bdev, struct blk_copy_payload *payload,
fcbd83ffa72af1e SelvaKumar S 2021-02-08 181 gfp_t gfp_mask, void **buf_p)
fcbd83ffa72af1e SelvaKumar S 2021-02-08 182 {
fcbd83ffa72af1e SelvaKumar S 2021-02-08 183 struct request_queue *q =
bdev_get_queue(bdev);
fcbd83ffa72af1e SelvaKumar S 2021-02-08 184 struct bio *bio, *parent = NULL;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 185 void *buf = NULL;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 186 bool is_vmalloc;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 187 int i, nr_srcs, copy_len, ret, cur_size,
t_len = 0;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 188
fcbd83ffa72af1e SelvaKumar S 2021-02-08 189 nr_srcs = payload->copy_range;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 190 copy_len = payload->copy_size <<
SECTOR_SHIFT;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 191
fcbd83ffa72af1e SelvaKumar S 2021-02-08 192 buf = kvmalloc(copy_len, gfp_mask);
fcbd83ffa72af1e SelvaKumar S 2021-02-08 193 if (!buf)
fcbd83ffa72af1e SelvaKumar S 2021-02-08 194 return -ENOMEM;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 195 is_vmalloc = is_vmalloc_addr(buf);
fcbd83ffa72af1e SelvaKumar S 2021-02-08 196
fcbd83ffa72af1e SelvaKumar S 2021-02-08 197 for (i = 0; i < nr_srcs; i++) {
Smatch is complaining that if "nr_secs" is zero then this leads to an
uninitialized variable warning. As a human reviewer I would worry that
payload->copy_range can be controlled by the user, but I don't have an
easy way to check.
fcbd83ffa72af1e SelvaKumar S 2021-02-08 198 cur_size = payload->range[i].len
<< SECTOR_SHIFT;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 199
fcbd83ffa72af1e SelvaKumar S 2021-02-08 200 bio = bio_map_kern(q, buf + t_len,
cur_size, gfp_mask);
fcbd83ffa72af1e SelvaKumar S 2021-02-08 201 if (IS_ERR(bio)) {
fcbd83ffa72af1e SelvaKumar S 2021-02-08 202 ret = PTR_ERR(bio);
fcbd83ffa72af1e SelvaKumar S 2021-02-08 203 goto out;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 204 }
fcbd83ffa72af1e SelvaKumar S 2021-02-08 205
fcbd83ffa72af1e SelvaKumar S 2021-02-08 206 bio->bi_iter.bi_sector =
payload->range[i].src;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 207 bio->bi_opf = REQ_OP_READ;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 208 bio_set_dev(bio, bdev);
fcbd83ffa72af1e SelvaKumar S 2021-02-08 209 bio->bi_end_io = NULL;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 210 bio->bi_private = NULL;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 211
fcbd83ffa72af1e SelvaKumar S 2021-02-08 212 if (parent) {
fcbd83ffa72af1e SelvaKumar S 2021-02-08 213 bio_chain(parent, bio);
fcbd83ffa72af1e SelvaKumar S 2021-02-08 214 submit_bio(parent);
fcbd83ffa72af1e SelvaKumar S 2021-02-08 215 }
fcbd83ffa72af1e SelvaKumar S 2021-02-08 216
fcbd83ffa72af1e SelvaKumar S 2021-02-08 217 parent = bio;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 218 t_len += cur_size;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 219 }
fcbd83ffa72af1e SelvaKumar S 2021-02-08 220
fcbd83ffa72af1e SelvaKumar S 2021-02-08 @221 ret = submit_bio_wait(bio);
^^^
fcbd83ffa72af1e SelvaKumar S 2021-02-08 222 bio_put(bio);
fcbd83ffa72af1e SelvaKumar S 2021-02-08 223 if (is_vmalloc)
fcbd83ffa72af1e SelvaKumar S 2021-02-08 224 invalidate_kernel_vmap_range(buf,
copy_len);
fcbd83ffa72af1e SelvaKumar S 2021-02-08 225 if (ret)
fcbd83ffa72af1e SelvaKumar S 2021-02-08 226 goto out;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 227
fcbd83ffa72af1e SelvaKumar S 2021-02-08 228 *buf_p = buf;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 229 return 0;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 230 out:
fcbd83ffa72af1e SelvaKumar S 2021-02-08 231 kvfree(buf);
fcbd83ffa72af1e SelvaKumar S 2021-02-08 232 return ret;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 233 }
[ snip ]
fcbd83ffa72af1e SelvaKumar S 2021-02-08 335 int blkdev_issue_copy(struct block_device
*bdev, int nr_srcs,
fcbd83ffa72af1e SelvaKumar S 2021-02-08 336 struct range_entry *src_rlist, struct
block_device *dest_bdev,
fcbd83ffa72af1e SelvaKumar S 2021-02-08 337 sector_t dest, gfp_t gfp_mask)
fcbd83ffa72af1e SelvaKumar S 2021-02-08 338 {
fcbd83ffa72af1e SelvaKumar S 2021-02-08 339 struct request_queue *q =
bdev_get_queue(bdev);
fcbd83ffa72af1e SelvaKumar S 2021-02-08 340 struct blk_copy_payload *payload;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 341 sector_t bs_mask, dest_sect;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 342 void *buf = NULL;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 343 int ret;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 344
fcbd83ffa72af1e SelvaKumar S 2021-02-08 345 ret = blk_prepare_payload(bdev, nr_srcs,
src_rlist, gfp_mask, &payload);
fcbd83ffa72af1e SelvaKumar S 2021-02-08 346 if (ret)
fcbd83ffa72af1e SelvaKumar S 2021-02-08 347 return ret;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 348
fcbd83ffa72af1e SelvaKumar S 2021-02-08 349 bs_mask =
(bdev_logical_block_size(dest_bdev) >> 9) - 1;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 350 if (dest & bs_mask) {
fcbd83ffa72af1e SelvaKumar S 2021-02-08 351 return -EINVAL;
^^^^^^^^^^^^^^^
fcbd83ffa72af1e SelvaKumar S 2021-02-08 @352 goto out;
^^^^^^^^
Memory leak of "payload".
fcbd83ffa72af1e SelvaKumar S 2021-02-08 353 }
fcbd83ffa72af1e SelvaKumar S 2021-02-08 354 dest_sect = dest >> SECTOR_SHIFT;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 355
fcbd83ffa72af1e SelvaKumar S 2021-02-08 356 if (bdev == dest_bdev &&
q->limits.copy_offload) {
fcbd83ffa72af1e SelvaKumar S 2021-02-08 357 ret = blk_copy_offload(bdev, payload,
dest_sect, gfp_mask);
fcbd83ffa72af1e SelvaKumar S 2021-02-08 358 if (ret)
fcbd83ffa72af1e SelvaKumar S 2021-02-08 359 goto out;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 360 } else {
fcbd83ffa72af1e SelvaKumar S 2021-02-08 361 ret = blk_read_to_buf(bdev, payload,
gfp_mask, &buf);
fcbd83ffa72af1e SelvaKumar S 2021-02-08 362 if (ret)
fcbd83ffa72af1e SelvaKumar S 2021-02-08 363 goto out;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 364 ret = blk_write_from_buf(dest_bdev, buf,
dest_sect,
fcbd83ffa72af1e SelvaKumar S 2021-02-08 365 payload->copy_size <<
SECTOR_SHIFT, gfp_mask);
fcbd83ffa72af1e SelvaKumar S 2021-02-08 366 }
fcbd83ffa72af1e SelvaKumar S 2021-02-08 367
fcbd83ffa72af1e SelvaKumar S 2021-02-08 368 if (buf)
fcbd83ffa72af1e SelvaKumar S 2021-02-08 369 kvfree(buf);
fcbd83ffa72af1e SelvaKumar S 2021-02-08 370 out:
fcbd83ffa72af1e SelvaKumar S 2021-02-08 371 kvfree(payload);
fcbd83ffa72af1e SelvaKumar S 2021-02-08 372 return ret;
fcbd83ffa72af1e SelvaKumar S 2021-02-08 373 }
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org