mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] btrfs: Fix -Wmaybe-uninitialized warning
@ 2025-12-18  8:16 Qiang Ma
  2025-12-18 20:37 ` David Sterba
  0 siblings, 1 reply; 3+ messages in thread
From: Qiang Ma @ 2025-12-18  8:16 UTC (permalink / raw)
  To: clm, dsterba; +Cc: linux-btrfs, linux-kernel, Qiang Ma

Fix a -Wmaybe-uninitialized warning by initializing
the variable to NULL.

$ make CFLAGS_tree-log.o=-Wmaybe-uninitialized

In file included from fs/btrfs/ctree.h:21,
                 from fs/btrfs/tree-log.c:12:
fs/btrfs/accessors.h: In function 'replay_one_buffer':
fs/btrfs/accessors.h:66:16: warning: 'inode_item' may be used uninitialized [-Wmaybe-uninitialized]
   66 |         return btrfs_get_##bits(eb, s, offsetof(type, member));         \
      |                ^~~~~~~~~~
fs/btrfs/tree-log.c:2803:42: note: 'inode_item' declared here
 2803 |                 struct btrfs_inode_item *inode_item;
      |                                          ^~~~~~~~~~

Warning was found when compiling using loongarch64-gcc 12.3.1.

Signed-off-by: Qiang Ma <maqianga@uniontech.com>
---
 fs/btrfs/tree-log.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 31edc93a383e..0d6faaaa70f1 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -2798,7 +2798,7 @@ static int replay_one_buffer(struct extent_buffer *eb,
 
 	nritems = btrfs_header_nritems(eb);
 	for (wc->log_slot = 0; wc->log_slot < nritems; wc->log_slot++) {
-		struct btrfs_inode_item *inode_item;
+		struct btrfs_inode_item *inode_item = NULL;
 
 		btrfs_item_key_to_cpu(eb, &wc->log_key, wc->log_slot);
 
-- 
2.20.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: Fix -Wmaybe-uninitialized warning
  2025-12-18  8:16 [PATCH] btrfs: Fix -Wmaybe-uninitialized warning Qiang Ma
@ 2025-12-18 20:37 ` David Sterba
  2025-12-19  3:11   ` Qiang Ma
  0 siblings, 1 reply; 3+ messages in thread
From: David Sterba @ 2025-12-18 20:37 UTC (permalink / raw)
  To: Qiang Ma; +Cc: clm, dsterba, linux-btrfs, linux-kernel

On Thu, Dec 18, 2025 at 04:16:18PM +0800, Qiang Ma wrote:
> Fix a -Wmaybe-uninitialized warning by initializing
> the variable to NULL.
> 
> $ make CFLAGS_tree-log.o=-Wmaybe-uninitialized
> 
> In file included from fs/btrfs/ctree.h:21,
>                  from fs/btrfs/tree-log.c:12:
> fs/btrfs/accessors.h: In function 'replay_one_buffer':
> fs/btrfs/accessors.h:66:16: warning: 'inode_item' may be used uninitialized [-Wmaybe-uninitialized]
>    66 |         return btrfs_get_##bits(eb, s, offsetof(type, member));         \
>       |                ^~~~~~~~~~
> fs/btrfs/tree-log.c:2803:42: note: 'inode_item' declared here
>  2803 |                 struct btrfs_inode_item *inode_item;
>       |                                          ^~~~~~~~~~
> 
> Warning was found when compiling using loongarch64-gcc 12.3.1.

We have the -Wmaybe-uninitialized warning enabled per fs/btrfs/
directory, there are no other known reports fixing the uninitialized
inode_item so this might be specific to loongarch gcc 12.x. I'll add the
patch to for-next as we still want to get all the warnings fixed, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: Fix -Wmaybe-uninitialized warning
  2025-12-18 20:37 ` David Sterba
@ 2025-12-19  3:11   ` Qiang Ma
  0 siblings, 0 replies; 3+ messages in thread
From: Qiang Ma @ 2025-12-19  3:11 UTC (permalink / raw)
  To: dsterba; +Cc: clm, dsterba, linux-btrfs, linux-kernel


在 2025/12/19 04:37, David Sterba 写道:
> On Thu, Dec 18, 2025 at 04:16:18PM +0800, Qiang Ma wrote:
>> Fix a -Wmaybe-uninitialized warning by initializing
>> the variable to NULL.
>>
>> $ make CFLAGS_tree-log.o=-Wmaybe-uninitialized
>>
>> In file included from fs/btrfs/ctree.h:21,
>>                   from fs/btrfs/tree-log.c:12:
>> fs/btrfs/accessors.h: In function 'replay_one_buffer':
>> fs/btrfs/accessors.h:66:16: warning: 'inode_item' may be used uninitialized [-Wmaybe-uninitialized]
>>     66 |         return btrfs_get_##bits(eb, s, offsetof(type, member));         \
>>        |                ^~~~~~~~~~
>> fs/btrfs/tree-log.c:2803:42: note: 'inode_item' declared here
>>   2803 |                 struct btrfs_inode_item *inode_item;
>>        |                                          ^~~~~~~~~~
>>
>> Warning was found when compiling using loongarch64-gcc 12.3.1.
> We have the -Wmaybe-uninitialized warning enabled per fs/btrfs/
> directory, there are no other known reports fixing the uninitialized
> inode_item so this might be specific to loongarch gcc 12.x. I'll add the
Yes, x86 and arm64 did not report this warning issue.
> patch to for-next as we still want to get all the warnings fixed, thanks.
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-12-19  3:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-18  8:16 [PATCH] btrfs: Fix -Wmaybe-uninitialized warning Qiang Ma
2025-12-18 20:37 ` David Sterba
2025-12-19  3:11   ` Qiang Ma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®