Linux-f2fs-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Chao Yu <chao@kernel.org>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <yuchao0@huawei.com>,
	linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net,
	Weichao Guo <guoweichao@huawei.com>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [f2fs-dev] [PATCH 04/28] f2fs: replace a build-time warning with runtime WARN_ON
Date: Wed, 26 Oct 2016 16:57:05 +0200	[thread overview]
Message-ID: <3766259.9ZsupLsmdk@wuerfel> (raw)
In-Reply-To: <c23b0800-c9db-d62c-fc05-d6f2208c01ff@kernel.org>

On Wednesday, October 26, 2016 10:05:00 PM CEST Chao Yu wrote:
> On 2016/10/18 6:05, Arnd Bergmann wrote:
> > gcc is unsure about the use of last_ofs_in_node, which might happen
> > without a prior initialization:
> > 
> > fs/f2fs//git/arm-soc/fs/f2fs/data.c: In function ‘f2fs_map_blocks’:
> > fs/f2fs/data.c:799:54: warning: ‘last_ofs_in_node’ may be used uninitialized in this function [-Wmaybe-uninitialized]
> >    if (prealloc && dn.ofs_in_node != last_ofs_in_node + 1) {
> 
> In each round of dnode block traverse, we will init 'prealloc' and then update
> 'prealloc' and 'last_ofs_in_node' together in below lines of f2fs_map_blocks:
>                         if (flag == F2FS_GET_BLOCK_PRE_AIO) {
>                                 if (blkaddr == NULL_ADDR) {
>                                         prealloc++;
>                                         last_ofs_in_node = dn.ofs_in_node;
>                                 }
>                         }
> 
> Then in below codes, it is safe to use 'last_ofs_in_node' since we will check
> 'prealloc' firstly, so if 'prealloc' is non-zero, 'last_ofs_in_node' must be valid.
>         if (prealloc && dn.ofs_in_node != last_ofs_in_node + 1) {
> 
> So I think we should not add WARN_ON there.

Ok, that make sense. Thanks for taking a closer look!

Should we just set last_ofs_in_node to the same value as ofs_in_node
before the loop?

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 9ae194f..14db4b7 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -716,7 +716,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
 	}
 
 	prealloc = 0;
-	ofs_in_node = dn.ofs_in_node;
+	last_ofs_in_node = ofs_in_node = dn.ofs_in_node;
 	end_offset = ADDRS_PER_PAGE(dn.node_page, inode);
 
 next_block:

	Arnd

  reply	other threads:[~2016-10-26 14:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-17 22:03 [PATCH 00/28] Reenable maybe-uninitialized warnings Arnd Bergmann
2016-10-17 22:05 ` [PATCH 04/28] f2fs: replace a build-time warning with runtime WARN_ON Arnd Bergmann
2016-10-26 14:05   ` [f2fs-dev] " Chao Yu
2016-10-26 14:57     ` Arnd Bergmann [this message]
2016-10-27 11:41       ` Chao Yu
2016-10-17 22:19 ` [PATCH 28/28] Kbuild: bring back -Wmaybe-uninitialized warning Arnd Bergmann
2016-10-18  5:08 ` [PATCH 00/28] Reenable maybe-uninitialized warnings Christoph Hellwig

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=3766259.9ZsupLsmdk@wuerfel \
    --to=arnd@arndb.de \
    --cc=chao@kernel.org \
    --cc=guoweichao@huawei.com \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=yuchao0@huawei.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