From: Qu Wenruo <wqu@suse.com>
To: Jiahao Li <lijiahao202609@163.com>, dsterba@suse.com, mason@kernel.org
Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
Jiahao Li <lijiahao1@kylinos.cn>
Subject: Re: [PATCH v1] btrfs: discard: fix warning for discard_state
Date: Mon, 14 Sep 2026 19:51:16 +0930 [thread overview]
Message-ID: <3f3209ea-44bf-4dc4-9567-d936703435d2@suse.com> (raw)
In-Reply-To: <20260914092222.1465563-1-lijiahao202609@163.com>
在 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;
prev parent reply other threads:[~2026-09-14 10:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 9:22 Jiahao Li
2026-09-14 10:21 ` Qu Wenruo [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3f3209ea-44bf-4dc4-9567-d936703435d2@suse.com \
--to=wqu@suse.com \
--cc=dsterba@suse.com \
--cc=lijiahao1@kylinos.cn \
--cc=lijiahao202609@163.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mason@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®