fs/ntfs: fix -Wmaybe-uninitialized warning in ntfs_ioctl_fitrim
PATCH 1/1 fs/ntfs: fix -Wmaybe-uninitialized warning in ntfs_ioctl_fitrim
From: huhai <[email protected]>
With CONFIG_KASAN, CONFIG_WERROR and -Wmaybe-uninitialized enabled, GCC 16.2 reports that range may be used uninitialized in ntfs_ioctl_fitrim():
CC [M] fs/ntfs/file.o
In file included from ./include/asm-generic/rwonce.h:26,
from ./arch/arm64/include/asm/rwonce.h:81,
from ./include/linux/compiler.h:369,
from ./arch/arm64/include/asm/current.h:5,
from ./include/linux/sched.h:12,
from ./include/linux/writeback.h:8,
from fs/ntfs/file.c:9:In function 'instrument_copy_from_user_before',
inlined from '_inline_copy_from_user' at ./include/linux/uaccess.h:184:2,
inlined from 'copy_from_user' at ./include/linux/uaccess.h:222:9,
inlined from 'ntfs_ioctl_fitrim' at fs/ntfs/file.c:845:6,
inlined from 'ntfs_ioctl' at fs/ntfs/file.c:876:10:./include/linux/kasan-checks.h:38:27: error: 'range' may be used uninitialized [-Werror=maybe-uninitialized]
38 | #define kasan_check_write __kasan_check_write./include/linux/instrumented.h:146:9: note: in expansion of macro 'kasan_check_write'
146 | kasan_check_write(to, n);
| ^~~~~~~~~~~~~~~~~
./include/linux/kasan-checks.h: In function 'ntfs_ioctl':
./include/linux/kasan-checks.h:20:6: note: by argument 1 of type 'const volatile void *' to '__kasan_check_write' declared here
20 | bool __kasan_check_write(const volatile void *p, unsigned int size);
| ^~~~~~~~~~~~~~~~~~~fs/ntfs/file.c:833:29: note: 'range' declared here
833 | struct fstrim_range range;
| ^~~~~
copy_from_user() initializes the entire structure on success, but GCC fails to recognize this after the KASAN checks are inlined. Zero-initialize range to avoid the false positive.
--- fs/ntfs/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs/file.c +1 -1
@@ -830,7 +830,7 @@ static int ntfs_ioctl_set_volume_label(struct file *filp, unsigned long arg)static int ntfs_ioctl_fitrim (struct ntfs_volume *vol,unsigned long arg) {struct fstrim_range __user *user_range; -struct fstrim_range range; +struct fstrim_range range = {};struct block_device *dev;int err;
Signature · 1 line
2.40.1
Quoted 47 lines · huhai
From: huhai <[email protected]>
With
CONFIG_KASAN,CONFIG_WERRORand -Wmaybe-uninitialized enabled, GCC 16.2 reports that range may be used uninitialized inntfs_ioctl_fitrim():CC [M]
fs/ntfs/file.o
In file included from./include/asm-generic/rwonce.h:26,from ./arch/arm64/include/asm/rwonce.h:81, from ./include/linux/compiler.h:369, from ./arch/arm64/include/asm/current.h:5, from ./include/linux/sched.h:12, from ./include/linux/writeback.h:8, from fs/ntfs/file.c:9:In function '
instrument_copy_from_user_before',
inlined from '_inline_copy_from_user' at./include/linux/uaccess.h:184:2,
inlined from 'copy_from_user' at./include/linux/uaccess.h:222:9,
inlined from 'ntfs_ioctl_fitrim' atfs/ntfs/file.c:845:6,
inlined from 'ntfs_ioctl' atfs/ntfs/file.c:876:10:./include/linux/kasan-checks.h:38:27: error: 'range' may be used uninitialized [-Werror=maybe-uninitialized]
38 | #definekasan_check_write__kasan_check_write./include/linux/instrumented.h:146:9: note: in expansion of macro 'kasan_check_write'146 | kasan_check_write(to, n); | ^~~~~~~~~~~~~~~~~ ./include/linux/kasan-checks.h: In function 'ntfs_ioctl': ./include/linux/kasan-checks.h:20:6: note: by argument 1 of type 'const volatile void *' to '__kasan_check_write' declared here 20 | bool __kasan_check_write(const volatile void *p, unsigned int size); | ^~~~~~~~~~~~~~~~~~~
fs/ntfs/file.c:833:29: note: 'range' declared here
833 | structfstrim_rangerange;
| ^~~~~
copy_from_user()initializes the entire structure on success, but GCC fails to recognize this after the KASAN checks are inlined. Zero-initialize range to avoid the false positive.Assisted-by Codex:gpt-5.6-solSigned-off-by huhai <[email protected]>--- fs/ntfs/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ntfs/file.c +0
-0
fs/ntfs/file.c static int ntfs_ioctl_set_volume_label(struct file *filp, unsigned long arg) · line 836
Quoted 8 lines
fs/ntfs/file.c +1
-1@@ -830,7 +830,7 @@ static int ntfs_ioctl_set_volume_label(struct file *filp, unsigned long arg)static int ntfs_ioctl_fitrim (struct ntfs_volume *vol,unsigned long arg) {struct fstrim_range __user *user_range; -struct fstrim_range range; +struct fstrim_range range = {};struct block_device *dev;int err;
Looks good to me.