Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965499AbcJQWIC (ORCPT ); Mon, 17 Oct 2016 18:08:02 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:50512 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965457AbcJQWH4 (ORCPT ); Mon, 17 Oct 2016 18:07:56 -0400 From: Arnd Bergmann To: Jaegeuk Kim , Chao Yu Cc: Linus Torvalds , linux-kernel@vger.kernel.org, Arnd Bergmann , Fan Li , Weichao Guo , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH 04/28] f2fs: replace a build-time warning with runtime WARN_ON Date: Tue, 18 Oct 2016 00:05:33 +0200 Message-Id: <20161017220557.1688282-4-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20161017220342.1627073-1-arnd@arndb.de> References: <20161017220342.1627073-1-arnd@arndb.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K0:JCGZR1TgDR1Y2+IMpcbN+gyrhzYMCT6Oq/cCGUuHVY3pm5H753x UMTO/lzGU2SuhaUiXn1UyXnlyvMzdW82U7sDAh6l4DV/mZqdDXQ2bE+1S9W/tUTMBZ+macp Qnltu+7R+qdLNw/az+HhI7FtUabb+il65xynm+N5ynJgjLPKV1/14zLPHVUZiAlFy1H2EoQ UdDCUXRA7pqTOPtNBF+zA== X-UI-Out-Filterresults: notjunk:1;V01:K0:tAeXN11ltUA=:5svkoX/nJVSodv2XuwSMcD sbDUSgchIm9x/GvarurTKno6utylp6OW1PXP4zQ+Ahkc4y8bU4WzZMkRNI/xnwPl8eO39BurX Th3r3jpbLFm0lguZF7ii0HWKeW8NXJ1BtgAAqU8VkkGWaNOpNpRZ64UvPRxmZt5ngW/FeD+sH 73+Nx95cE+AWSHVmMXjGUqSvEveeew9SusFS5WVO4WAnQWlm2VAwhzA4rtg0Qasp5HdL3ltQ+ sLuYSePTTC6uSOfQ8+30qsX7XeDE7EX3IB5BPyWXmJY9Uma/c5BJ6Vz2EHaYrcy4A3UksQItv T5TlGhHjE2zVIAentbV2epOP5v0EL1LtcD4y8RLvCdi269phLQuC/hyph6f6x3eNfjgGi98P9 FrPChQYDExbusMsHVK4N6TfjyqUEb6kIiXrv5setxTgxh+Yth/jCOKPNm92jiJhwqRNvT9Znv L1PrdhOSxu3zp3VQz5TD6KKLChge3G82KtrSrg52EsxM1ensh4A26jnKFS4jTqF0iIfx4/QiY tDXZrwWUQSutidjK+TcNdADtHktAFJwJQJaWYVkkf32kU2/sAFrKVBj85BdMTsBpy2C756jnO FFNsUyxwD6a0dcR8BchyCoYvowL8g1x4c1LNYe21/tXg/SCbMQ+eL6h5dzpR0jNAEfxUeRTVt alzcPyW1HZNuSzryHnUzOvfQkf0o+7lqqYxGC9w2z3nBnbKDhd25XxnugJkGWw8h9bc3RSbb3 R+evFUDDx6+zGLIA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2096 Lines: 56 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) { I'm not sure about it either, so to shut up the warning I initialize it to a known invalid -1u and later check for this, so we get a runtime warning if we ever hit the uninitialized case. It would be much better to reorganize the code in some form that made it obvious to both the compiler and the reader that this variable use it ok. Since I only see the warning with gcc-4.9 but not any later version, it's possible that the compiler is actually smarter than I am here and has learned to see the code as correct, in which case this patch could just be disregarded. It would certainly be helpful to get an opinion from the maintainers on the matter. Fixes: 46008c6d4232 ("f2fs: support in batch multi blocks preallocation") Cc: Chao Yu Cc: Jaegeuk Kim Signed-off-by: Arnd Bergmann --- fs/f2fs/data.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 9ae194f..1b17de2 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -696,6 +696,12 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, goto out; } + /* + * FIXME: without this, we get "warning: ‘last_ofs_in_node’ may be + * used uninitialized". It's not clear whether that can actually + * happen, so there is now a WARN_ON() checking for this. + */ + last_ofs_in_node = -1u; next_dnode: if (create) f2fs_lock_op(sbi); @@ -796,6 +802,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, allocated = dn.node_changed; map->m_len += dn.ofs_in_node - ofs_in_node; + WARN_ON(last_ofs_in_node == -1u); if (prealloc && dn.ofs_in_node != last_ofs_in_node + 1) { err = -ENOSPC; goto sync_out; -- 2.9.0