Linux-bcachefs Archive mirror
 help / color / mirror / Atom feed
From: Kent Overstreet <kent.overstreet@linux.dev>
To: Hongbo Li <lihongbo22@huawei.com>
Cc: bfoster@redhat.com, linux-bcachefs@vger.kernel.org
Subject: Re: [PATCH v2 1/2] bcachefs: eliminate the uninitialized compilation warning in bch2_reconstruct_snapshots
Date: Fri, 26 Apr 2024 00:04:40 -0400	[thread overview]
Message-ID: <klmvmcxhce2yd2xdmeyrnvxdvh25jykwwpzov7volswdzrrff3@4bpqb6erpimf> (raw)
In-Reply-To: <20240426032136.2551471-2-lihongbo22@huawei.com>

On Fri, Apr 26, 2024 at 11:21:35AM +0800, Hongbo Li wrote:
> When compiling the bcachefs-tools, the following compilation warning
> is reported:
>     libbcachefs/snapshot.c: In function ‘bch2_reconstruct_snapshots’:
>     libbcachefs/snapshot.c:915:19: warning: ‘tree_id’ may be used uninitialized in this function [-Wmaybe-uninitialized]
>       915 |  snapshot->v.tree = cpu_to_le32(tree_id);
>     libbcachefs/snapshot.c:903:6: note: ‘tree_id’ was declared here
>       903 |  u32 tree_id;
>        |      ^~~~~~~
> 
> This is a false alert, because @tree_id is changed in
> bch2_snapshot_tree_create after it returns 0. And if this function
> returns other value, @tree_id wouldn't be used. Thus there should
> be nothing wrong in logical.
> 
> Although the report itself is a false alert, we can still make it more
> explicit by setting the initial value of @tree_id to 0 (an invalid
> tree ID).
> 
> Fixes: a292be3b68f3 ("bcachefs: Reconstruct missing snapshot nodes")
> Signed-off-by: Hongbo Li <lihongbo22@huawei.com>

this works - applied

> ---
> v2:
>   - Revise the code based on Kent's reviews.
> 
> v1: https://lore.kernel.org/all/20240419074851.1583392-2-lihongbo22@huawei.com/T/#u
> ---
> ---
>  fs/bcachefs/snapshot.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/bcachefs/snapshot.c b/fs/bcachefs/snapshot.c
> index 2368218070d4..3aa4686cc71f 100644
> --- a/fs/bcachefs/snapshot.c
> +++ b/fs/bcachefs/snapshot.c
> @@ -900,7 +900,8 @@ static int check_snapshot_exists(struct btree_trans *trans, u32 id)
>  	if (bch2_snapshot_equiv(c, id))
>  		return 0;
>  
> -	u32 tree_id;
> +	/* 0 is an invalid tree ID */
> +	u32 tree_id = 0;
>  	int ret = bch2_snapshot_tree_create(trans, id, 0, &tree_id);
>  	if (ret)
>  		return ret;
> -- 
> 2.34.1
> 

  reply	other threads:[~2024-04-26  4:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-26  3:21 [PATCH v2 0/2] eliminate the uninitialized compilation warning Hongbo Li
2024-04-26  3:21 ` [PATCH v2 1/2] bcachefs: eliminate the uninitialized compilation warning in bch2_reconstruct_snapshots Hongbo Li
2024-04-26  4:04   ` Kent Overstreet [this message]
2024-04-26  3:21 ` [PATCH v2 2/2] bcachefs: eliminate the uninitialized compilation warning in __do_six_trylock Hongbo Li
2024-04-26  4:04   ` Kent Overstreet
2024-04-26  6:09     ` Hongbo Li

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=klmvmcxhce2yd2xdmeyrnvxdvh25jykwwpzov7volswdzrrff3@4bpqb6erpimf \
    --to=kent.overstreet@linux.dev \
    --cc=bfoster@redhat.com \
    --cc=lihongbo22@huawei.com \
    --cc=linux-bcachefs@vger.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).