* [PATCH v1] btrfs: discard: fix warning for discard_state
@ 2026-09-14 9:22 Jiahao Li
2026-09-14 10:21 ` Qu Wenruo
0 siblings, 1 reply; 2+ messages in thread
From: Jiahao Li @ 2026-09-14 9:22 UTC (permalink / raw)
To: dsterba, mason; +Cc: linux-btrfs, linux-kernel, Jiahao Li
From: Jiahao Li <lijiahao1@kylinos.cn>
Building with -Werror=mabe-uninitialized fails:
fs/btrfs/discard.c:553:9: error: 'discard_state' may be used
uninitialized [-Werror=maybe-uninitialized]
The compiler cannot prove that discard_state is assigned on every path
before it is read. Initialize it to BTRFS_DISCARD_EXTENTS, which is the
state the variable holds when the loop is first entered, this does not
change runtime behavior, so the warning is gone and the value is always
well defined.
Signed-off-by: Jiahao Li <lijiahao1@kylinos.cn>
---
fs/btrfs/discard.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/btrfs/discard.c b/fs/btrfs/discard.c
index 1c304bf473e5..413a804ff46b 100644
--- a/fs/btrfs/discard.c
+++ b/fs/btrfs/discard.c
@@ -519,7 +519,7 @@ static void btrfs_discard_workfn(struct work_struct *work)
{
struct btrfs_discard_ctl *discard_ctl;
struct btrfs_block_group *block_group;
- enum btrfs_discard_state discard_state;
+ enum btrfs_discard_state discard_state = BTRFS_DISCARD_EXTENTS;
int discard_index = 0;
u64 trimmed = 0;
u64 minlen = 0;
--
2.25.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v1] btrfs: discard: fix warning for discard_state
2026-09-14 9:22 [PATCH v1] btrfs: discard: fix warning for discard_state Jiahao Li
@ 2026-09-14 10:21 ` Qu Wenruo
0 siblings, 0 replies; 2+ messages in thread
From: Qu Wenruo @ 2026-09-14 10:21 UTC (permalink / raw)
To: Jiahao Li, dsterba, mason; +Cc: linux-btrfs, linux-kernel, Jiahao Li
在 2026/9/14 18:52, Jiahao Li 写道:
> From: Jiahao Li <lijiahao1@kylinos.cn>
>
> Building with -Werror=mabe-uninitialized fails:
> fs/btrfs/discard.c:553:9: error: 'discard_state' may be used
> uninitialized [-Werror=maybe-uninitialized]
>
> The compiler cannot prove that discard_state is assigned on every path
> before it is read.
Compiler and its version, a lot of times such false alerts are just
compiler version dependent.
In my case, gcc 16.2.1 failed to reproduced this false alert.
Initialize it to BTRFS_DISCARD_EXTENTS, which is the
> state the variable holds when the loop is first entered, this does not
> change runtime behavior, so the warning is gone and the value is always
> well defined.
It's a false alert.
Firstly if peek_discard_list() didn't find a bg, btrfs_discard_workfn()
returned immediately.
Secondly if a bg is found in peek_discard_list(), *discard_state is
fetched from bg's discard_state.
So all paths should be fine.
>
> Signed-off-by: Jiahao Li <lijiahao1@kylinos.cn>
> ---
> fs/btrfs/discard.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/discard.c b/fs/btrfs/discard.c
> index 1c304bf473e5..413a804ff46b 100644
> --- a/fs/btrfs/discard.c
> +++ b/fs/btrfs/discard.c
> @@ -519,7 +519,7 @@ static void btrfs_discard_workfn(struct work_struct *work)
> {
> struct btrfs_discard_ctl *discard_ctl;
> struct btrfs_block_group *block_group;
> - enum btrfs_discard_state discard_state;
> + enum btrfs_discard_state discard_state = BTRFS_DISCARD_EXTENTS;
> int discard_index = 0;
> u64 trimmed = 0;
> u64 minlen = 0;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-14 10:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-14 9:22 [PATCH v1] btrfs: discard: fix warning for discard_state Jiahao Li
2026-09-14 10:21 ` Qu Wenruo
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®