[xiang-linux:erofs/chunk 8/8] fs/erofs/data.c:93:6: warning: variable 'err' is used uninitialized whenever 'if' condition is true

From: kernel test robot
Date: Sun Aug 15 2021 - 22:34:32 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/xiang/linux.git erofs/chunk
head: a915f0e209270389efab942fcd446e31a98c4062
commit: a915f0e209270389efab942fcd446e31a98c4062 [8/8] erofs: support reading chunk-based files
config: powerpc-randconfig-r013-20210816 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 7776b19eed44906e9973bfb240b6279d6feaab41)
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
# install powerpc cross compiling tool for clang build
# apt-get install binutils-powerpc-linux-gnu
# https://git.kernel.org/pub/scm/linux/kernel/git/xiang/linux.git/commit/?id=a915f0e209270389efab942fcd446e31a98c4062
git remote add xiang-linux https://git.kernel.org/pub/scm/linux/kernel/git/xiang/linux.git
git fetch --no-tags xiang-linux erofs/chunk
git checkout a915f0e209270389efab942fcd446e31a98c4062
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=powerpc

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

All warnings (new ones prefixed by >>):

In file included from arch/powerpc/include/asm/hardirq.h:6:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/powerpc/include/asm/io.h:619:
arch/powerpc/include/asm/io-defs.h:45:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
DEF_PCI_AC_NORET(insw, (unsigned long p, void *b, unsigned long c),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/include/asm/io.h:616:3: note: expanded from macro 'DEF_PCI_AC_NORET'
__do_##name al; \
^~~~~~~~~~~~~~
<scratch space>:209:1: note: expanded from here
__do_insw
^
arch/powerpc/include/asm/io.h:557:56: note: expanded from macro '__do_insw'
#define __do_insw(p, b, n) readsw((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
~~~~~~~~~~~~~~~~~~~~~^
In file included from fs/erofs/data.c:7:
In file included from fs/erofs/internal.h:13:
In file included from include/linux/pagemap.h:11:
In file included from include/linux/highmem.h:10:
In file included from include/linux/hardirq.h:11:
In file included from arch/powerpc/include/asm/hardirq.h:6:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/powerpc/include/asm/io.h:619:
arch/powerpc/include/asm/io-defs.h:47:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
DEF_PCI_AC_NORET(insl, (unsigned long p, void *b, unsigned long c),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/include/asm/io.h:616:3: note: expanded from macro 'DEF_PCI_AC_NORET'
__do_##name al; \
^~~~~~~~~~~~~~
<scratch space>:211:1: note: expanded from here
__do_insl
^
arch/powerpc/include/asm/io.h:558:56: note: expanded from macro '__do_insl'
#define __do_insl(p, b, n) readsl((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
~~~~~~~~~~~~~~~~~~~~~^
In file included from fs/erofs/data.c:7:
In file included from fs/erofs/internal.h:13:
In file included from include/linux/pagemap.h:11:
In file included from include/linux/highmem.h:10:
In file included from include/linux/hardirq.h:11:
In file included from arch/powerpc/include/asm/hardirq.h:6:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/powerpc/include/asm/io.h:619:
arch/powerpc/include/asm/io-defs.h:49:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
DEF_PCI_AC_NORET(outsb, (unsigned long p, const void *b, unsigned long c),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/include/asm/io.h:616:3: note: expanded from macro 'DEF_PCI_AC_NORET'
__do_##name al; \
^~~~~~~~~~~~~~
<scratch space>:213:1: note: expanded from here
__do_outsb
^
arch/powerpc/include/asm/io.h:559:58: note: expanded from macro '__do_outsb'
#define __do_outsb(p, b, n) writesb((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
~~~~~~~~~~~~~~~~~~~~~^
In file included from fs/erofs/data.c:7:
In file included from fs/erofs/internal.h:13:
In file included from include/linux/pagemap.h:11:
In file included from include/linux/highmem.h:10:
In file included from include/linux/hardirq.h:11:
In file included from arch/powerpc/include/asm/hardirq.h:6:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/powerpc/include/asm/io.h:619:
arch/powerpc/include/asm/io-defs.h:51:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
DEF_PCI_AC_NORET(outsw, (unsigned long p, const void *b, unsigned long c),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/include/asm/io.h:616:3: note: expanded from macro 'DEF_PCI_AC_NORET'
__do_##name al; \
^~~~~~~~~~~~~~
<scratch space>:215:1: note: expanded from here
__do_outsw
^
arch/powerpc/include/asm/io.h:560:58: note: expanded from macro '__do_outsw'
#define __do_outsw(p, b, n) writesw((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
~~~~~~~~~~~~~~~~~~~~~^
In file included from fs/erofs/data.c:7:
In file included from fs/erofs/internal.h:13:
In file included from include/linux/pagemap.h:11:
In file included from include/linux/highmem.h:10:
In file included from include/linux/hardirq.h:11:
In file included from arch/powerpc/include/asm/hardirq.h:6:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/powerpc/include/asm/io.h:619:
arch/powerpc/include/asm/io-defs.h:53:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
DEF_PCI_AC_NORET(outsl, (unsigned long p, const void *b, unsigned long c),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/include/asm/io.h:616:3: note: expanded from macro 'DEF_PCI_AC_NORET'
__do_##name al; \
^~~~~~~~~~~~~~
<scratch space>:217:1: note: expanded from here
__do_outsl
^
arch/powerpc/include/asm/io.h:561:58: note: expanded from macro '__do_outsl'
#define __do_outsl(p, b, n) writesl((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
~~~~~~~~~~~~~~~~~~~~~^
>> fs/erofs/data.c:93:6: warning: variable 'err' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
if (map->m_la >= inode->i_size) {
^~~~~~~~~~~~~~~~~~~~~~~~~~
fs/erofs/data.c:151:9: note: uninitialized use occurs here
return err;
^~~
fs/erofs/data.c:93:2: note: remove the 'if' if its condition is always false
if (map->m_la >= inode->i_size) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fs/erofs/data.c:91:9: note: initialize the variable 'err' to silence this warning
int err;
^
= 0
7 warnings generated.


vim +93 fs/erofs/data.c

80
81 static int erofs_map_blocks(struct inode *inode,
82 struct erofs_map_blocks *map, int flags)
83 {
84 struct super_block *sb = inode->i_sb;
85 struct erofs_inode *vi = EROFS_I(inode);
86 struct erofs_inode_chunk_index *idx;
87 struct page *page;
88 u64 chunknr;
89 unsigned int unit;
90 erofs_off_t pos;
91 int err;
92
> 93 if (map->m_la >= inode->i_size) {
94 map->m_flags = 0;
95 map->m_plen = 0;
96 goto out;
97 }
98
99 if (vi->datalayout != EROFS_INODE_CHUNK_BASED)
100 return erofs_map_blocks_flatmode(inode, map, flags);
101
102 if (vi->chunkformat & EROFS_CHUNK_FORMAT_INDEXES)
103 unit = sizeof(*idx); /* chunk index */
104 else
105 unit = 4; /* chunk index */
106
107 chunknr = map->m_la >> vi->chunkbits;
108 pos = ALIGN(iloc(EROFS_SB(sb), vi->nid) + vi->inode_isize +
109 vi->xattr_isize, unit) + unit * chunknr;
110
111 page = erofs_get_meta_page(inode->i_sb, erofs_blknr(pos));
112 if (IS_ERR(page))
113 return PTR_ERR(page);
114
115 err = 0;
116 map->m_plen = min_t(erofs_off_t, 1 << vi->chunkbits,
117 inode->i_size - map->m_la);
118 if (!(vi->chunkformat & EROFS_CHUNK_FORMAT_INDEXES)) {
119 __le32 *blkaddr = page_address(page) + erofs_blkoff(pos);
120
121 if (le32_to_cpu(*blkaddr) == EROFS_NULL_ADDR) {
122 map->m_flags = 0;
123 } else {
124 map->m_pa = blknr_to_addr(le32_to_cpu(*blkaddr));
125 map->m_flags = EROFS_MAP_MAPPED;
126 }
127 goto out_unlock;
128 }
129 idx = page_address(page) + erofs_blkoff(pos);
130 switch (le32_to_cpu(idx->blkaddr)) {
131 case EROFS_NULL_ADDR:
132 map->m_flags = 0;
133 break;
134 default:
135 if (idx->device_id) {
136 erofs_err(sb, "invalid device %u @ %llu for nid %llu",
137 le32_to_cpu(idx->device_id),
138 chunknr, vi->nid);
139 err = -EINVAL;
140 goto out;
141 }
142 map->m_pa = blknr_to_addr(le32_to_cpu(idx->blkaddr));
143 map->m_flags = EROFS_MAP_MAPPED;
144 break;
145 }
146 out_unlock:
147 unlock_page(page);
148 put_page(page);
149 out:
150 map->m_llen = map->m_plen;
151 return err;
152 }
153

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

Attachment: .config.gz
Description: application/gzip