[<prev] [next>] [day] [month] [year] [list]
Message-ID: <30200c4e-21e8-4454-a947-01d228f154a1@kili.mountain>
Date: Mon, 20 Mar 2023 08:44:48 +0300
From: Dan Carpenter <error27@...il.com>
To: oe-kbuild@...ts.linux.dev,
Damien Le Moal <damien.lemoal@...nsource.wdc.com>
Cc: lkp@...el.com, oe-kbuild-all@...ts.linux.dev,
linux-kernel@...r.kernel.org,
Johannes Thumshirn <johannes.thumshirn@....com>
Subject: fs/zonefs/file.c:441 zonefs_file_dio_append() error: uninitialized
symbol 'size'.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: a3671bd86a9770e34969522d29bb30a1b66fd88a
commit: 4008e2a0b01aba982356fd15b128a47bf11bd9c7 zonefs: Reorganize code
config: nios2-randconfig-m031-20230319 (https://download.01.org/0day-ci/archive/20230319/202303191227.GL8Dprbi-lkp@intel.com/config)
compiler: nios2-linux-gcc (GCC) 12.1.0
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@...el.com>
| Reported-by: Dan Carpenter <error27@...il.com>
| Link: https://lore.kernel.org/r/202303191227.GL8Dprbi-lkp@intel.com/
New smatch warnings:
fs/zonefs/file.c:441 zonefs_file_dio_append() error: uninitialized symbol 'size'.
vim +/size +441 fs/zonefs/file.c
4008e2a0b01aba Damien Le Moal 2022-11-25 378 static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from)
4008e2a0b01aba Damien Le Moal 2022-11-25 379 {
4008e2a0b01aba Damien Le Moal 2022-11-25 380 struct inode *inode = file_inode(iocb->ki_filp);
4008e2a0b01aba Damien Le Moal 2022-11-25 381 struct zonefs_inode_info *zi = ZONEFS_I(inode);
4008e2a0b01aba Damien Le Moal 2022-11-25 382 struct block_device *bdev = inode->i_sb->s_bdev;
4008e2a0b01aba Damien Le Moal 2022-11-25 383 unsigned int max = bdev_max_zone_append_sectors(bdev);
4008e2a0b01aba Damien Le Moal 2022-11-25 384 struct bio *bio;
4008e2a0b01aba Damien Le Moal 2022-11-25 385 ssize_t size;
4008e2a0b01aba Damien Le Moal 2022-11-25 386 int nr_pages;
4008e2a0b01aba Damien Le Moal 2022-11-25 387 ssize_t ret;
4008e2a0b01aba Damien Le Moal 2022-11-25 388
4008e2a0b01aba Damien Le Moal 2022-11-25 389 max = ALIGN_DOWN(max << SECTOR_SHIFT, inode->i_sb->s_blocksize);
4008e2a0b01aba Damien Le Moal 2022-11-25 390 iov_iter_truncate(from, max);
4008e2a0b01aba Damien Le Moal 2022-11-25 391
4008e2a0b01aba Damien Le Moal 2022-11-25 392 nr_pages = iov_iter_npages(from, BIO_MAX_VECS);
4008e2a0b01aba Damien Le Moal 2022-11-25 393 if (!nr_pages)
4008e2a0b01aba Damien Le Moal 2022-11-25 394 return 0;
4008e2a0b01aba Damien Le Moal 2022-11-25 395
4008e2a0b01aba Damien Le Moal 2022-11-25 396 bio = bio_alloc(bdev, nr_pages,
4008e2a0b01aba Damien Le Moal 2022-11-25 397 REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE, GFP_NOFS);
4008e2a0b01aba Damien Le Moal 2022-11-25 398 bio->bi_iter.bi_sector = zi->i_zsector;
4008e2a0b01aba Damien Le Moal 2022-11-25 399 bio->bi_ioprio = iocb->ki_ioprio;
4008e2a0b01aba Damien Le Moal 2022-11-25 400 if (iocb_is_dsync(iocb))
4008e2a0b01aba Damien Le Moal 2022-11-25 401 bio->bi_opf |= REQ_FUA;
4008e2a0b01aba Damien Le Moal 2022-11-25 402
4008e2a0b01aba Damien Le Moal 2022-11-25 403 ret = bio_iov_iter_get_pages(bio, from);
4008e2a0b01aba Damien Le Moal 2022-11-25 404 if (unlikely(ret))
4008e2a0b01aba Damien Le Moal 2022-11-25 405 goto out_release;
This is a false positive because bio_iov_iter_get_pages() is returning
negatives on this error path. Building the cross function database
would silence this warning. Still it's not just Smatch which is going
to complain and GCC extensions are most likely going to initialize size
to zero anyway.
4008e2a0b01aba Damien Le Moal 2022-11-25 406
4008e2a0b01aba Damien Le Moal 2022-11-25 407 size = bio->bi_iter.bi_size;
4008e2a0b01aba Damien Le Moal 2022-11-25 408 task_io_account_write(size);
4008e2a0b01aba Damien Le Moal 2022-11-25 409
4008e2a0b01aba Damien Le Moal 2022-11-25 410 if (iocb->ki_flags & IOCB_HIPRI)
4008e2a0b01aba Damien Le Moal 2022-11-25 411 bio_set_polled(bio, iocb);
4008e2a0b01aba Damien Le Moal 2022-11-25 412
4008e2a0b01aba Damien Le Moal 2022-11-25 413 ret = submit_bio_wait(bio);
4008e2a0b01aba Damien Le Moal 2022-11-25 414
4008e2a0b01aba Damien Le Moal 2022-11-25 415 /*
4008e2a0b01aba Damien Le Moal 2022-11-25 416 * If the file zone was written underneath the file system, the zone
4008e2a0b01aba Damien Le Moal 2022-11-25 417 * write pointer may not be where we expect it to be, but the zone
4008e2a0b01aba Damien Le Moal 2022-11-25 418 * append write can still succeed. So check manually that we wrote where
4008e2a0b01aba Damien Le Moal 2022-11-25 419 * we intended to, that is, at zi->i_wpoffset.
4008e2a0b01aba Damien Le Moal 2022-11-25 420 */
4008e2a0b01aba Damien Le Moal 2022-11-25 421 if (!ret) {
4008e2a0b01aba Damien Le Moal 2022-11-25 422 sector_t wpsector =
4008e2a0b01aba Damien Le Moal 2022-11-25 423 zi->i_zsector + (zi->i_wpoffset >> SECTOR_SHIFT);
4008e2a0b01aba Damien Le Moal 2022-11-25 424
4008e2a0b01aba Damien Le Moal 2022-11-25 425 if (bio->bi_iter.bi_sector != wpsector) {
4008e2a0b01aba Damien Le Moal 2022-11-25 426 zonefs_warn(inode->i_sb,
4008e2a0b01aba Damien Le Moal 2022-11-25 427 "Corrupted write pointer %llu for zone at %llu\n",
4008e2a0b01aba Damien Le Moal 2022-11-25 428 wpsector, zi->i_zsector);
4008e2a0b01aba Damien Le Moal 2022-11-25 429 ret = -EIO;
4008e2a0b01aba Damien Le Moal 2022-11-25 430 }
4008e2a0b01aba Damien Le Moal 2022-11-25 431 }
4008e2a0b01aba Damien Le Moal 2022-11-25 432
4008e2a0b01aba Damien Le Moal 2022-11-25 433 zonefs_file_write_dio_end_io(iocb, size, ret, 0);
4008e2a0b01aba Damien Le Moal 2022-11-25 434 trace_zonefs_file_dio_append(inode, size, ret);
4008e2a0b01aba Damien Le Moal 2022-11-25 435
4008e2a0b01aba Damien Le Moal 2022-11-25 436 out_release:
4008e2a0b01aba Damien Le Moal 2022-11-25 437 bio_release_pages(bio, false);
4008e2a0b01aba Damien Le Moal 2022-11-25 438 bio_put(bio);
4008e2a0b01aba Damien Le Moal 2022-11-25 439
4008e2a0b01aba Damien Le Moal 2022-11-25 440 if (ret >= 0) {
4008e2a0b01aba Damien Le Moal 2022-11-25 @441 iocb->ki_pos += size;
4008e2a0b01aba Damien Le Moal 2022-11-25 442 return size;
4008e2a0b01aba Damien Le Moal 2022-11-25 443 }
4008e2a0b01aba Damien Le Moal 2022-11-25 444
4008e2a0b01aba Damien Le Moal 2022-11-25 445 return ret;
4008e2a0b01aba Damien Le Moal 2022-11-25 446 }
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
Powered by blists - more mailing lists