linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Zhao Lei <zhaolei@cn.fujitsu.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: fix a compiler warning of may be used uninitialized
Date: Tue, 29 Sep 2015 16:21:34 +0200	[thread overview]
Message-ID: <20150929142134.GC11442@twin.jikos.cz> (raw)
In-Reply-To: <09827c6fe97dbbeb585e6214f7e40699061b8fc6.1441178370.git.zhaolei@cn.fujitsu.com>

On Wed, Sep 02, 2015 at 03:19:59PM +0800, Zhao Lei wrote:
> Not real problem, just avoid warning of:
>  fs/btrfs/inode-map.c: In function 'btrfs_unpin_free_ino':
>  fs/btrfs/inode-map.c:252: warning: 'count' may be used uninitialized in this function
> In gcc 4.8.3
> 
> Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
> ---
>  fs/btrfs/inode-map.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c
> index d4a582a..e094e3b 100644
> --- a/fs/btrfs/inode-map.c
> +++ b/fs/btrfs/inode-map.c
> @@ -249,7 +249,7 @@ void btrfs_unpin_free_ino(struct btrfs_root *root)
>  	spinlock_t *rbroot_lock = &root->free_ino_pinned->tree_lock;
>  	struct btrfs_free_space *info;
>  	struct rb_node *n;
> -	u64 count;
> +	u64 count = 0;

AFAICS the codepath that would use uninitialized value of count is not
reachable:

		    add_to_ctl = true

270                 if (info->offset > root->ino_cache_progress)
271                         add_to_ctl = false;
272                 else if (info->offset + info->bytes > root->ino_cache_progress)
273                         count = root->ino_cache_progress - info->offset + 1;
274                 else
275                         count = info->bytes;
276
277                 rb_erase(&info->offset_index, rbroot);
278                 spin_unlock(rbroot_lock);
279                 if (add_to_ctl)
280                         __btrfs_add_free_space(ctl, info->offset, count);

count is defined iff add_to_ctl == true, so the patch is not necessary. And I'm
not quite sure that 0 passed down to __btrfs_add_free_space as 'bytes' makes
sense at all.

  reply	other threads:[~2015-09-29 14:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-02  7:19 [PATCH] btrfs: fix a compiler warning of may be used uninitialized Zhao Lei
2015-09-29 14:21 ` David Sterba [this message]
2015-09-30  3:55   ` Zhao Lei
2015-09-30  8:18     ` Holger Hoffstätte
2015-09-30 14:58     ` David Sterba

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=20150929142134.GC11442@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=zhaolei@cn.fujitsu.com \
    /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 NNTP newsgroup(s).