Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752855AbcJZO5u convert rfc822-to-8bit (ORCPT ); Wed, 26 Oct 2016 10:57:50 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:53132 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752008AbcJZO5t (ORCPT ); Wed, 26 Oct 2016 10:57:49 -0400 From: Arnd Bergmann To: Chao Yu Cc: Jaegeuk Kim , Chao Yu , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, Weichao Guo , Linus Torvalds 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 Message-ID: <3766259.9ZsupLsmdk@wuerfel> User-Agent: KMail/5.1.3 (Linux/4.4.0-34-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: References: <20161017220342.1627073-1-arnd@arndb.de> <20161017220557.1688282-4-arnd@arndb.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset="UTF-8" X-Provags-ID: V03:K0:58dJ9ys2QBUV3IXCmatTBjqdJ5yfAR41h7mpbPbeiyP7lfeBDoW CYG9JEuOMWtcZ1/injAADwKd8RZrsKgqU25Y/fOQ/GsTmLZzI+hqlVR3DBRX5mLB/zwwlxd e6oI4mXdST9V1sYBAmqHO8kqLlsHEN0Bq5ezfoQYrnY/zvGVVESctQSVIG0oZUoI70kBwqH flXhVhTnnElkZC6DMf5sg== X-UI-Out-Filterresults: notjunk:1;V01:K0:DFJE1DWKvZg=:e3Fh0yZYT2zLJeMMOplrFe akMkmo/csaEqZRlFLr/OVMKAl76s/Mm+6FIPeC48p8wmXmbGGUoDp+iMjkY9s65SdmhnSZArT W9unxsHvC7ft6GBlgfuPN73umr0CUHgaXbnHY1Y4MtdaeKSCSwjKjgU1cJvls7KZEbAQZG0QZ zUOtBaUhBMtlUmpcj4VJBtWxsGU06QqBJnTEh0jwcinSQgUs3adzxf7rU5aK7QdaQIMtnix9v 56z23BU+MG5I/fD2wU42PgrAnlAz622VSChuAwbejqJvPQmBodjSpLk3Mz8dP/Azr4LsBivuG A3honFD1ixS4ZxpiZfGWI2bFSbfHxfcBdrHJPevci51B83b9nvJxR0BcgVi7/nIO4Ei/wvt4k 07QWZT8WvMAFT0uE5VPBCb5GuN255Fq6tQJTZrHpIF1RKiJoV6E7cb8xMF1irEtXcKDvW9hX2 qmGnkb/uVaxGn1TiM1/pAecvMoDH4Ks+CMA+KBYGtnbR9Hsosr3Tl0mFsVwp0LKLXEbkmRzDM 3EheheT8GWGH0ElL+n5oEo408fPHvEHPbeYcZ32Qs6RLBbyuBRBUyQxCCkhxDF9cR3cWAaZvj R48cOxtqwJJvkPXsE72K6dOoqG92pawVrczCQmxxSUIub6yNBRjz3V+l+7KMAPWaf0v3gvNkq WvfQ8yvS3tbenD0LwBojFe24lZwzaPXvKfZ+YpgrGgehm0JnYdZBh9bpBG44x5MLp1D52Ci2N 917SwWEz9taF+5ee Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1786 Lines: 44 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