[willy-pagecache:for-next 174/179] fs/nilfs2/inode.c:227:13: warning: variable 'nr_dirty' is used uninitialized whenever 'if' condition is false

From: kernel test robot
Date: Tue Mar 15 2022 - 07:12:49 EST


tree: git://git.infradead.org/users/willy/pagecache for-next
head: af564d7369d44fbbe697a5f631fe3bba5ebecd59
commit: 248cfe55743b4293f9fa06384e35581121d60ee1 [174/179] nilfs: Convert nilfs_set_page_dirty() to nilfs_dirty_folio()
config: i386-randconfig-a012-20220314 (https://download.01.org/0day-ci/archive/20220315/202203151941.WVgUZDhE-lkp@xxxxxxxxx/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project a6b2f50fb47da3baeee10b1906da6e30ac5d26ec)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
git remote add willy-pagecache git://git.infradead.org/users/willy/pagecache
git fetch --no-tags willy-pagecache for-next
git checkout 248cfe55743b4293f9fa06384e35581121d60ee1
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash fs/nilfs2/ mm/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>

All warnings (new ones prefixed by >>):

>> fs/nilfs2/inode.c:227:13: warning: variable 'nr_dirty' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
} else if (ret) {
^~~
fs/nilfs2/inode.c:232:6: note: uninitialized use occurs here
if (nr_dirty)
^~~~~~~~
fs/nilfs2/inode.c:227:9: note: remove the 'if' if its condition is always true
} else if (ret) {
^~~~~~~~~
fs/nilfs2/inode.c:207:23: note: initialize the variable 'nr_dirty' to silence this warning
unsigned int nr_dirty;
^
= 0
1 warning generated.


vim +227 fs/nilfs2/inode.c

05fe58fdc10df9e Ryusuke Konishi 2009-04-06 201
248cfe55743b429 Matthew Wilcox (Oracle 2022-02-09 202) static bool nilfs_dirty_folio(struct address_space *mapping,
248cfe55743b429 Matthew Wilcox (Oracle 2022-02-09 203) struct folio *folio)
05fe58fdc10df9e Ryusuke Konishi 2009-04-06 204 {
248cfe55743b429 Matthew Wilcox (Oracle 2022-02-09 205) struct inode *inode = mapping->host;
248cfe55743b429 Matthew Wilcox (Oracle 2022-02-09 206) struct buffer_head *head;
248cfe55743b429 Matthew Wilcox (Oracle 2022-02-09 207) unsigned int nr_dirty;
248cfe55743b429 Matthew Wilcox (Oracle 2022-02-09 208) bool ret = filemap_dirty_folio(mapping, folio);
05fe58fdc10df9e Ryusuke Konishi 2009-04-06 209
136e8770cd5d1fe Ryusuke Konishi 2013-05-24 210 /*
248cfe55743b429 Matthew Wilcox (Oracle 2022-02-09 211) * The page may not be locked, eg if called from try_to_unmap_one()
136e8770cd5d1fe Ryusuke Konishi 2013-05-24 212 */
248cfe55743b429 Matthew Wilcox (Oracle 2022-02-09 213) spin_lock(&mapping->private_lock);
248cfe55743b429 Matthew Wilcox (Oracle 2022-02-09 214) head = folio_buffers(folio);
248cfe55743b429 Matthew Wilcox (Oracle 2022-02-09 215) if (head) {
248cfe55743b429 Matthew Wilcox (Oracle 2022-02-09 216) struct buffer_head *bh = head;
248cfe55743b429 Matthew Wilcox (Oracle 2022-02-09 217)
248cfe55743b429 Matthew Wilcox (Oracle 2022-02-09 218) nr_dirty = 0;
136e8770cd5d1fe Ryusuke Konishi 2013-05-24 219 do {
136e8770cd5d1fe Ryusuke Konishi 2013-05-24 220 /* Do not mark hole blocks dirty */
136e8770cd5d1fe Ryusuke Konishi 2013-05-24 221 if (buffer_dirty(bh) || !buffer_mapped(bh))
136e8770cd5d1fe Ryusuke Konishi 2013-05-24 222 continue;
136e8770cd5d1fe Ryusuke Konishi 2013-05-24 223
136e8770cd5d1fe Ryusuke Konishi 2013-05-24 224 set_buffer_dirty(bh);
136e8770cd5d1fe Ryusuke Konishi 2013-05-24 225 nr_dirty++;
136e8770cd5d1fe Ryusuke Konishi 2013-05-24 226 } while (bh = bh->b_this_page, bh != head);
56d7acc792c0d98 Andreas Rohner 2014-09-25 @227 } else if (ret) {
248cfe55743b429 Matthew Wilcox (Oracle 2022-02-09 228) nr_dirty = 1 << (PAGE_SHIFT - inode->i_blkbits);
248cfe55743b429 Matthew Wilcox (Oracle 2022-02-09 229) }
248cfe55743b429 Matthew Wilcox (Oracle 2022-02-09 230) spin_unlock(&mapping->private_lock);
56d7acc792c0d98 Andreas Rohner 2014-09-25 231
248cfe55743b429 Matthew Wilcox (Oracle 2022-02-09 232) if (nr_dirty)
bcbc8c648d6cc88 Ryusuke Konishi 2010-12-27 233 nilfs_set_file_dirty(inode, nr_dirty);
05fe58fdc10df9e Ryusuke Konishi 2009-04-06 234 return ret;
05fe58fdc10df9e Ryusuke Konishi 2009-04-06 235 }
05fe58fdc10df9e Ryusuke Konishi 2009-04-06 236

:::::: The code at line 227 was first introduced by commit
:::::: 56d7acc792c0d98f38f22058671ee715ff197023 nilfs2: fix data loss with mmap()

:::::: TO: Andreas Rohner <andreas.rohner@xxxxxxx>
:::::: CC: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>

---
0-DAY CI Kernel Test Service
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx