fs: ext4: fix uninitialized symbols
PATCH 1/1 fs: ext4: fix uninitialized symbols
Fix the issue detected by the smatch tool.
fs/ext4/inode.c:3583 ext4_map_blocks_atomic_write_slow() error: uninitialized symbol 'next_pblk'. fs/ext4/namei.c:1776 ext4_lookup() error: uninitialized symbol 'de'. fs/ext4/namei.c:1829 ext4_get_parent() error: uninitialized symbol 'de'. fs/ext4/namei.c:3162 ext4_rmdir() error: uninitialized symbol 'de'. fs/ext4/namei.c:3242 __ext4_unlink() error: uninitialized symbol 'de'. fs/ext4/namei.c:3697 ext4_find_delete_entry() error: uninitialized symbol 'de'.
Tested with compilation only.
These changes enhance code clarity, address static analysis tool errors.
--- fs/ext4/inode.c | 2 +- fs/ext4/namei.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)
fs/ext4/inode.c +1 -1
@@ -3544,7 +3544,7 @@ static int ext4_map_blocks_atomic_write_slow(handle_t *handle,ext4_lblk_t m_lblk = map->m_lblk;unsigned int m_len = map->m_len;unsigned int mapped_len =0 , m_flags =0 ; -ext4_fsblk_t next_pblk; +ext4_fsblk_t next_pblk =NULL ;bool check_next_pblk = false;int ret =0 ;
fs/ext4/namei.c +5 -5
@@ -1762,7 +1762,7 @@ static struct buffer_head * ext4_dx_find_entry(struct inode *dir,static struct dentry *ext4_lookup (struct inode *dir,struct dentry *dentry,unsigned int flags) {struct inode *inode; -struct ext4_dir_entry_2 *de; +struct ext4_dir_entry_2 *de =NULL ;struct buffer_head *bh;if (dentry->d_name.len >EXT4_NAME_LEN )
@@ -1818,7 +1818,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsistruct dentry *ext4_get_parent (struct dentry *child) {__u32 ino; -struct ext4_dir_entry_2 * de; +struct ext4_dir_entry_2 * de =NULL ;struct buffer_head *bh; bh =ext4_find_entry (d_inode (child), &dotdot_name, &de,NULL );
@@ -3133,7 +3133,7 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)int retval;struct inode *inode;struct buffer_head *bh; -struct ext4_dir_entry_2 *de; +struct ext4_dir_entry_2 *de =NULL ;handle_t *handle =NULL ; retval =ext4_emergency_state (dir->i_sb);
@@ -3224,7 +3224,7 @@ int __ext4_unlink(struct inode *dir, const struct qstr *d_name, {int retval = -ENOENT ;struct buffer_head *bh; -struct ext4_dir_entry_2 *de; +struct ext4_dir_entry_2 *de =NULL ;handle_t *handle;int skip_remove_dentry =0 ;
@@ -3688,7 +3688,7 @@ static int ext4_find_delete_entry(handle_t *handle, struct inode *dir, {int retval = -ENOENT ;struct buffer_head *bh; -struct ext4_dir_entry_2 *de; +struct ext4_dir_entry_2 *de =NULL ; bh =ext4_find_entry (dir, d_name, &de,NULL );if (IS_ERR (bh))
Signature · 1 line
2.43.0
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Ranganath,
kernel test robot noticed the following build warnings:
[auto build test WARNING on tytso-ext4/dev]
[also build test WARNING on linus/master v6.17 next-20251010] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Ranganath-V-N/fs-ext4-fix-uninitialized-symbols/20251010-065232 base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev patch link: https://lore.kernel.org/r/20251008171614.12129-1-vnranganath.20%40gmail.com patch subject: [PATCH] fs: ext4: fix uninitialized symbols config: sparc-randconfig-002-20251010 (https://download.01.org/0day-ci/archive/20251011/[email protected]/config) compiler: sparc64-linux-gcc (GCC) 8.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251011/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from include/uapi/linux/posix_types.h:5,
from include/uapi/linux/types.h:14,
from include/linux/types.h:6,
from include/linux/kasan-checks.h:5,
from include/asm-generic/rwonce.h:26,
from ./arch/sparc/include/generated/asm/rwonce.h:1,
from include/linux/compiler.h:382,
from arch/sparc/include/asm/bug.h:6,
from include/linux/bug.h:5,
from include/linux/vfsdebug.h:5,
from include/linux/fs.h:5,
from fs/ext4/inode.c:22:
fs/ext4/inode.c: In function 'ext4_map_blocks_atomic_write_slow':
>> include/linux/stddef.h:8:14: warning: initialization of 'ext4_fsblk_t' {aka 'long long unsigned int'} from 'void *' makes integer from pointer without a cast [-Wint-conversion]
#define NULL ((void *)0)
^
fs/ext4/inode.c:3547:27: note: in expansion of macro 'NULL'
ext4_fsblk_t next_pblk = NULL;
^~~~
--
In file included from include/uapi/linux/posix_types.h:5,
from include/uapi/linux/types.h:14,
from include/linux/types.h:6,
from include/linux/kasan-checks.h:5,
from include/asm-generic/rwonce.h:26,
from arch/sparc/include/generated/asm/rwonce.h:1,
from include/linux/compiler.h:382,
from arch/sparc/include/asm/bug.h:6,
from include/linux/bug.h:5,
from include/linux/vfsdebug.h:5,
from include/linux/fs.h:5,
from inode.c:22:
inode.c: In function 'ext4_map_blocks_atomic_write_slow':
>> include/linux/stddef.h:8:14: warning: initialization of 'ext4_fsblk_t' {aka 'long long unsigned int'} from 'void *' makes integer from pointer without a cast [-Wint-conversion]
#define NULL ((void *)0)
^
inode.c:3547:27: note: in expansion of macro 'NULL'
ext4_fsblk_t next_pblk = NULL;
^~~~vim +8 include/linux/stddef.h
^1da177e4c3f41 Linus Torvalds 2005-04-16 6 ^1da177e4c3f41 Linus Torvalds 2005-04-16 7 #undef NULL ^1da177e4c3f41 Linus Torvalds 2005-04-16 @8 #define NULL ((void *)0)
6e218287432472 Richard Knutsson 2006-09-30 9
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Ranganath,
kernel test robot noticed the following build errors:
[auto build test ERROR on tytso-ext4/dev]
[also build test ERROR on linus/master v6.17 next-20251010] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Ranganath-V-N/fs-ext4-fix-uninitialized-symbols/20251010-065232 base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev patch link: https://lore.kernel.org/r/20251008171614.12129-1-vnranganath.20%40gmail.com patch subject: [PATCH] fs: ext4: fix uninitialized symbols config: x86_64-defconfig (https://download.01.org/0day-ci/archive/20251011/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251011/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from include/uapi/linux/posix_types.h:5,
from include/uapi/linux/types.h:14,
from include/linux/types.h:6,
from include/linux/objtool_types.h:7,
from include/linux/objtool.h:5,
from include/linux/instrumentation.h:7,
from arch/x86/include/asm/bug.h:6,
from include/linux/bug.h:5,
from include/linux/vfsdebug.h:5,
from include/linux/fs.h:5,
from fs/ext4/inode.c:22:
fs/ext4/inode.c: In function 'ext4_map_blocks_atomic_write_slow':
>> include/linux/stddef.h:8:14: error: initialization of 'ext4_fsblk_t' {aka 'long long unsigned int'} from 'void *' makes integer from pointer without a cast [-Wint-conversion]
8 | #define NULL ((void *)0)
| ^
fs/ext4/inode.c:3547:34: note: in expansion of macro 'NULL'
3547 | ext4_fsblk_t next_pblk = NULL;
| ^~~~vim +8 include/linux/stddef.h
^1da177e4c3f41 Linus Torvalds 2005-04-16 6 ^1da177e4c3f41 Linus Torvalds 2005-04-16 7 #undef NULL ^1da177e4c3f41 Linus Torvalds 2005-04-16 @8 #define NULL ((void *)0)
6e218287432472 Richard Knutsson 2006-09-30 9
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v2 1/1 fs: ext4: fix uninitialized symbols
Fix the issue detected by the smatch tool.
fs/ext4/inode.c:3583 ext4_map_blocks_atomic_write_slow() error: uninitialized symbol 'next_pblk'. fs/ext4/namei.c:1776 ext4_lookup() error: uninitialized symbol 'de'. fs/ext4/namei.c:1829 ext4_get_parent() error: uninitialized symbol 'de'. fs/ext4/namei.c:3162 ext4_rmdir() error: uninitialized symbol 'de'. fs/ext4/namei.c:3242 __ext4_unlink() error: uninitialized symbol 'de'. fs/ext4/namei.c:3697 ext4_find_delete_entry() error: uninitialized symbol 'de'.
These changes enhance code clarity, address static analysis tool errors.
---
v2:
corrected the kernel test robot noticed build errors.
fs/ext4/inode.c | 2 +- fs/ext4/namei.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)
fs/ext4/inode.c +1 -1
@@ -3544,7 +3544,7 @@ static int ext4_map_blocks_atomic_write_slow(handle_t *handle,ext4_lblk_t m_lblk = map->m_lblk;unsigned int m_len = map->m_len;unsigned int mapped_len =0 , m_flags =0 ; -ext4_fsblk_t next_pblk; +ext4_fsblk_t next_pblk =0 ;bool check_next_pblk = false;int ret =0 ;
fs/ext4/namei.c +5 -5
@@ -1762,7 +1762,7 @@ static struct buffer_head * ext4_dx_find_entry(struct inode *dir,static struct dentry *ext4_lookup (struct inode *dir,struct dentry *dentry,unsigned int flags) {struct inode *inode; -struct ext4_dir_entry_2 *de; +struct ext4_dir_entry_2 *de =NULL ;struct buffer_head *bh;if (dentry->d_name.len >EXT4_NAME_LEN )
@@ -1818,7 +1818,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsistruct dentry *ext4_get_parent (struct dentry *child) {__u32 ino; -struct ext4_dir_entry_2 * de; +struct ext4_dir_entry_2 * de =NULL ;struct buffer_head *bh; bh =ext4_find_entry (d_inode (child), &dotdot_name, &de,NULL );
@@ -3133,7 +3133,7 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)int retval;struct inode *inode;struct buffer_head *bh; -struct ext4_dir_entry_2 *de; +struct ext4_dir_entry_2 *de =NULL ;handle_t *handle =NULL ; retval =ext4_emergency_state (dir->i_sb);
@@ -3224,7 +3224,7 @@ int __ext4_unlink(struct inode *dir, const struct qstr *d_name, {int retval = -ENOENT ;struct buffer_head *bh; -struct ext4_dir_entry_2 *de; +struct ext4_dir_entry_2 *de =NULL ;handle_t *handle;int skip_remove_dentry =0 ;
@@ -3688,7 +3688,7 @@ static int ext4_find_delete_entry(handle_t *handle, struct inode *dir, {int retval = -ENOENT ;struct buffer_head *bh; -struct ext4_dir_entry_2 *de; +struct ext4_dir_entry_2 *de =NULL ; bh =ext4_find_entry (dir, d_name, &de,NULL );if (IS_ERR (bh))
Signature · 1 line
2.43.0
Theodore Ts'o
maintainerQuoted 3 lines · Ranganath V N
Fix the issue detected by the smatch tool.
fs/ext4/inode.c:3583ext4_map_blocks_atomic_write_slow()error: uninitialized symbol 'next_pblk'.
This one is valid, and I agree with your proposed changed. (Although the worst that will happen is that in case of an ENOSPC error comined with a corrpted file system the warning message may print an uninitialized value. So not a big eal, but we might as well fix it.)
Quoted 1 line
fs/ext4/namei.c:1776ext4_lookup()error: uninitialized symbol 'de'.
This is a false positive for smatch. There isn't actualy a prolem here, because all of these funtions are calling ext4_find_entry() or ext4_lookup_entry(), and the callers will not try to dereference the pointer passed into *res_dir ('de') if the function has either returned NULL or an ERR_PTR(), and that's in fact correct.
I don't especially mind the fix (but I do wish smatch could be smarter). Out of curiosity, if we move the *res_dir = NULL from __ext4_find_entry() and move it so it's unconditionally set in ext4_find_entry() and ext4_lookup_entry(), is that sufficient to make smatch stop complaining?
- Ted
Quoted 10 lines · Ranganath V N
Fix the issue detected by the smatch tool.
fs/ext4/inode.c:3583ext4_map_blocks_atomic_write_slow()error: uninitialized symbol 'next_pblk'.fs/ext4/namei.c:1776ext4_lookup()error: uninitialized symbol 'de'.fs/ext4/namei.c:1829ext4_get_parent()error: uninitialized symbol 'de'.fs/ext4/namei.c:3162ext4_rmdir()error: uninitialized symbol 'de'.fs/ext4/namei.c:3242__ext4_unlink()error: uninitialized symbol 'de'.fs/ext4/namei.c:3697ext4_find_delete_entry()error: uninitialized symbol 'de'.[...]
Applied, thanks!
[1/1] fs: ext4: fix uninitialized symbols
commit: 6640d552185f7c11235c64a832004db9af119b2d
Best regards,
Signature · 1 line
Theodore Ts'o <[email protected]>
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Ranganath,
kernel test robot noticed the following build warnings:
[auto build test WARNING on tytso-ext4/dev]
[also build test WARNING on linus/master v6.17 next-20251010] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Ranganath-V-N/fs-ext4-fix-uninitialized-symbols/20251010-065232 base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev patch link: https://lore.kernel.org/r/20251008171614.12129-1-vnranganath.20%40gmail.com patch subject: [PATCH] fs: ext4: fix uninitialized symbols config: i386-randconfig-063-20251011 (https://download.01.org/0day-ci/archive/20251011/[email protected]/config) compiler: gcc-13 (Debian 13.3.0-16) 13.3.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251011/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
>> fs/ext4/inode.c:3547:34: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned long long [usertype] next_pblk @@ got void * @@
fs/ext4/inode.c:3547:34: sparse: expected unsigned long long [usertype] next_pblk
fs/ext4/inode.c:3547:34: sparse: got void *
vim +3547 fs/ext4/inode.c
3540
3541 static int ext4_map_blocks_atomic_write_slow(handle_t *handle,
3542 struct inode *inode, struct ext4_map_blocks *map)
3543 {
3544 ext4_lblk_t m_lblk = map->m_lblk;
3545 unsigned int m_len = map->m_len;
3546 unsigned int mapped_len = 0, m_flags = 0;
> 3547 ext4_fsblk_t next_pblk = NULL;
3548 bool check_next_pblk = false;
3549 int ret = 0;
3550
3551 WARN_ON_ONCE(!ext4_has_feature_bigalloc(inode->i_sb));
3552
3553 /*
3554 * This is a slow path in case of mixed mapping. We use
3555 * EXT4_GET_BLOCKS_CREATE_ZERO flag here to make sure we get a single
3556 * contiguous mapped mapping. This will ensure any unwritten or hole
3557 * regions within the requested range is zeroed out and we return
3558 * a single contiguous mapped extent.
3559 */
3560 m_flags = EXT4_GET_BLOCKS_CREATE_ZERO;
3561
3562 do {
3563 ret = ext4_map_blocks(handle, inode, map, m_flags);
3564 if (ret < 0 && ret != -ENOSPC)
3565 goto out_err;
3566 /*
3567 * This should never happen, but let's return an error code to
3568 * avoid an infinite loop in here.
3569 */
3570 if (ret == 0) {
3571 ret = -EFSCORRUPTED;
3572 ext4_warning_inode(inode,
3573 "ext4_map_blocks() couldn't allocate blocks m_flags: 0x%x, ret:%d",
3574 m_flags, ret);
3575 goto out_err;
3576 }
3577 /*
3578 * With bigalloc we should never get ENOSPC nor discontiguous
3579 * physical extents.
3580 */
3581 if ((check_next_pblk && next_pblk != map->m_pblk) ||
3582 ret == -ENOSPC) {
3583 ext4_warning_inode(inode,
3584 "Non-contiguous allocation detected: expected %llu, got %llu, "
3585 "or ext4_map_blocks() returned out of space ret: %d",
3586 next_pblk, map->m_pblk, ret);
3587 ret = -EFSCORRUPTED;
3588 goto out_err;
3589 }
3590 next_pblk = map->m_pblk + map->m_len;
3591 check_next_pblk = true;
3592
3593 mapped_len += map->m_len;
3594 map->m_lblk += map->m_len;
3595 map->m_len = m_len - mapped_len;
3596 } while (mapped_len < m_len);
3597
3598 /*
3599 * We might have done some work in above loop, so we need to query the
3600 * start of the physical extent, based on the origin m_lblk and m_len.
3601 * Let's also ensure we were able to allocate the required range for
3602 * mixed mapping case.
3603 */
3604 map->m_lblk = m_lblk;
3605 map->m_len = m_len;
3606 map->m_flags = 0;
3607
3608 ret = ext4_map_blocks(handle, inode, map,
3609 EXT4_GET_BLOCKS_QUERY_LAST_IN_LEAF);
3610 if (ret != m_len) {
3611 ext4_warning_inode(inode,
3612 "allocation failed for atomic write request m_lblk:%u, m_len:%u, ret:%d\n",
3613 m_lblk, m_len, ret);
3614 ret = -EINVAL;
3615 }
3616 return ret;
3617
3618 out_err:
3619 /* reset map before returning an error */
3620 map->m_lblk = m_lblk;
3621 map->m_len = m_len;
3622 map->m_flags = 0;
3623 return ret;
3624 }
3625
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki