* [PATCH] btrfs: initialize location to fix -Wmaybe-uninitialized in btrfs_lookup_dentry()
@ 2024-07-29 20:06 David Sterba
2024-07-29 21:34 ` Qu Wenruo
2024-07-30 7:09 ` Geert Uytterhoeven
0 siblings, 2 replies; 4+ messages in thread
From: David Sterba @ 2024-07-29 20:06 UTC (permalink / raw)
To: linux-btrfs; +Cc: geert, David Sterba
Some arch + compiler combinations report a potentially unused variable
location in btrfs_lookup_dentry(). This is a false alert as the variable
is passed by value and always valid or there's an error. The compilers
cannot probably reason about that although btrfs_inode_by_name() is in
the same file.
> + /kisskb/src/fs/btrfs/inode.c: error: 'location.objectid' may be used
+uninitialized in this function [-Werror=maybe-uninitialized]: => 5603:9
> + /kisskb/src/fs/btrfs/inode.c: error: 'location.type' may be used
+uninitialized in this function [-Werror=maybe-uninitialized]: => 5674:5
m68k-gcc8/m68k-allmodconfig
mips-gcc8/mips-allmodconfig
powerpc-gcc5/powerpc-all{mod,yes}config
powerpc-gcc5/ppc64_defconfig
Initialize it to zero, this should fix the warnings and won't change the
behaviour as btrfs_inode_by_name() accepts only a root or inode item
types, otherwise returns an error.
Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Link: https://lore.kernel.org/linux-btrfs/bd4e9928-17b3-9257-8ba7-6b7f9bbb639a@linux-m68k.org/
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/inode.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 32010127710d..333b0e8587a2 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -5667,7 +5667,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
struct inode *inode;
struct btrfs_root *root = BTRFS_I(dir)->root;
struct btrfs_root *sub_root = root;
- struct btrfs_key location;
+ struct btrfs_key location = { 0 };
u8 di_type = 0;
int ret = 0;
--
2.45.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] btrfs: initialize location to fix -Wmaybe-uninitialized in btrfs_lookup_dentry()
2024-07-29 20:06 [PATCH] btrfs: initialize location to fix -Wmaybe-uninitialized in btrfs_lookup_dentry() David Sterba
@ 2024-07-29 21:34 ` Qu Wenruo
2024-07-29 22:06 ` David Sterba
2024-07-30 7:09 ` Geert Uytterhoeven
1 sibling, 1 reply; 4+ messages in thread
From: Qu Wenruo @ 2024-07-29 21:34 UTC (permalink / raw)
To: David Sterba, linux-btrfs; +Cc: geert
在 2024/7/30 05:36, David Sterba 写道:
> Some arch + compiler combinations report a potentially unused variable
> location in btrfs_lookup_dentry(). This is a false alert as the variable
> is passed by value and always valid or there's an error. The compilers
> cannot probably reason about that although btrfs_inode_by_name() is in
> the same file.
>
> > + /kisskb/src/fs/btrfs/inode.c: error: 'location.objectid' may be used
> +uninitialized in this function [-Werror=maybe-uninitialized]: => 5603:9
> > + /kisskb/src/fs/btrfs/inode.c: error: 'location.type' may be used
> +uninitialized in this function [-Werror=maybe-uninitialized]: => 5674:5
>
> m68k-gcc8/m68k-allmodconfig
> mips-gcc8/mips-allmodconfig
> powerpc-gcc5/powerpc-all{mod,yes}config
> powerpc-gcc5/ppc64_defconfig
>
> Initialize it to zero, this should fix the warnings and won't change the
> behaviour as btrfs_inode_by_name() accepts only a root or inode item
> types, otherwise returns an error.
>
> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
> Link: https://lore.kernel.org/linux-btrfs/bd4e9928-17b3-9257-8ba7-6b7f9bbb639a@linux-m68k.org/
> Signed-off-by: David Sterba <dsterba@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Although I hate to update our code for bad compilers, I guess it's
unavoidable anyway.
Thanks,
Qu
> ---
> fs/btrfs/inode.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 32010127710d..333b0e8587a2 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -5667,7 +5667,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
> struct inode *inode;
> struct btrfs_root *root = BTRFS_I(dir)->root;
> struct btrfs_root *sub_root = root;
> - struct btrfs_key location;
> + struct btrfs_key location = { 0 };
> u8 di_type = 0;
> int ret = 0;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] btrfs: initialize location to fix -Wmaybe-uninitialized in btrfs_lookup_dentry()
2024-07-29 21:34 ` Qu Wenruo
@ 2024-07-29 22:06 ` David Sterba
0 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2024-07-29 22:06 UTC (permalink / raw)
To: Qu Wenruo; +Cc: David Sterba, linux-btrfs, geert
On Tue, Jul 30, 2024 at 07:04:36AM +0930, Qu Wenruo wrote:
>
>
> 在 2024/7/30 05:36, David Sterba 写道:
> > Some arch + compiler combinations report a potentially unused variable
> > location in btrfs_lookup_dentry(). This is a false alert as the variable
> > is passed by value and always valid or there's an error. The compilers
> > cannot probably reason about that although btrfs_inode_by_name() is in
> > the same file.
> >
> > > + /kisskb/src/fs/btrfs/inode.c: error: 'location.objectid' may be used
> > +uninitialized in this function [-Werror=maybe-uninitialized]: => 5603:9
> > > + /kisskb/src/fs/btrfs/inode.c: error: 'location.type' may be used
> > +uninitialized in this function [-Werror=maybe-uninitialized]: => 5674:5
> >
> > m68k-gcc8/m68k-allmodconfig
> > mips-gcc8/mips-allmodconfig
> > powerpc-gcc5/powerpc-all{mod,yes}config
> > powerpc-gcc5/ppc64_defconfig
> >
> > Initialize it to zero, this should fix the warnings and won't change the
> > behaviour as btrfs_inode_by_name() accepts only a root or inode item
> > types, otherwise returns an error.
> >
> > Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
> > Link: https://lore.kernel.org/linux-btrfs/bd4e9928-17b3-9257-8ba7-6b7f9bbb639a@linux-m68k.org/
> > Signed-off-by: David Sterba <dsterba@suse.com>
>
> Reviewed-by: Qu Wenruo <wqu@suse.com>
>
> Although I hate to update our code for bad compilers, I guess it's
> unavoidable anyway.
Yeah, but the number of such fixups is bearable, we have added like one
per release.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] btrfs: initialize location to fix -Wmaybe-uninitialized in btrfs_lookup_dentry()
2024-07-29 20:06 [PATCH] btrfs: initialize location to fix -Wmaybe-uninitialized in btrfs_lookup_dentry() David Sterba
2024-07-29 21:34 ` Qu Wenruo
@ 2024-07-30 7:09 ` Geert Uytterhoeven
1 sibling, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2024-07-30 7:09 UTC (permalink / raw)
To: David Sterba; +Cc: linux-btrfs
Hi David,
On Mon, Jul 29, 2024 at 10:06 PM David Sterba <dsterba@suse.com> wrote:
> Some arch + compiler combinations report a potentially unused variable
> location in btrfs_lookup_dentry(). This is a false alert as the variable
> is passed by value and always valid or there's an error. The compilers
> cannot probably reason about that although btrfs_inode_by_name() is in
> the same file.
>
> > + /kisskb/src/fs/btrfs/inode.c: error: 'location.objectid' may be used
> +uninitialized in this function [-Werror=maybe-uninitialized]: => 5603:9
> > + /kisskb/src/fs/btrfs/inode.c: error: 'location.type' may be used
> +uninitialized in this function [-Werror=maybe-uninitialized]: => 5674:5
>
> m68k-gcc8/m68k-allmodconfig
> mips-gcc8/mips-allmodconfig
> powerpc-gcc5/powerpc-all{mod,yes}config
> powerpc-gcc5/ppc64_defconfig
>
> Initialize it to zero, this should fix the warnings and won't change the
> behaviour as btrfs_inode_by_name() accepts only a root or inode item
> types, otherwise returns an error.
>
> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
> Link: https://lore.kernel.org/linux-btrfs/bd4e9928-17b3-9257-8ba7-6b7f9bbb639a@linux-m68k.org/
> Signed-off-by: David Sterba <dsterba@suse.com>
> ---
> fs/btrfs/inode.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 32010127710d..333b0e8587a2 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -5667,7 +5667,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
> struct inode *inode;
> struct btrfs_root *root = BTRFS_I(dir)->root;
> struct btrfs_root *sub_root = root;
> - struct btrfs_key location;
> + struct btrfs_key location = { 0 };
> u8 di_type = 0;
> int ret = 0;
>
Thanks, this gets rid of the failure for m68k/allmodconfig
(gcc version 8.4.0 (Ubuntu 8.4.0-3ubuntu1) and 9.5.0 (Ubuntu
9.5.0-1ubuntu1~22.04)).
On m68k, it didn't show up with gcc 10, 11, and 12.
Also, enabling CONFIG_CC_OPTIMIZE_FOR_SIZE fixed it for gcc 8/9.
Tested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-07-30 7:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-29 20:06 [PATCH] btrfs: initialize location to fix -Wmaybe-uninitialized in btrfs_lookup_dentry() David Sterba
2024-07-29 21:34 ` Qu Wenruo
2024-07-29 22:06 ` David Sterba
2024-07-30 7:09 ` Geert Uytterhoeven
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox