From patchwork Mon Nov 28 21:05:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 9450425 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 238F76071C for ; Mon, 28 Nov 2016 21:06:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1619D27F95 for ; Mon, 28 Nov 2016 21:06:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A58128066; Mon, 28 Nov 2016 21:06:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D6F327F95 for ; Mon, 28 Nov 2016 21:06:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755239AbcK1VGf (ORCPT ); Mon, 28 Nov 2016 16:06:35 -0500 Received: from mout.kundenserver.de ([212.227.126.131]:63913 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755199AbcK1VGd (ORCPT ); Mon, 28 Nov 2016 16:06:33 -0500 Received: from wuerfel.lan ([78.43.21.235]) by mrelayeu.kundenserver.de (mreue005 [212.227.15.129]) with ESMTPA (Nemesis) id 0LrGGm-1cq7Sf1ync-013AZn; Mon, 28 Nov 2016 22:06:09 +0100 From: Arnd Bergmann To: Chris Mason , Josef Bacik , David Sterba Cc: Arnd Bergmann , Filipe Manana , Al Viro , Chandan Rajendra , Jeff Mahoney , Wang Xiaoguang , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] btrfs: fix uninitialized variable access after ASSERT Date: Mon, 28 Nov 2016 22:05:40 +0100 Message-Id: <20161128210606.2321419-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:bgb8bUOA53D/S9Tgoak8SWZSnKAjgwJ/snqo0qycQ300VJZuBvd j4whvBCCYZQEZ6PtnC0aKhsNcmRkF9NJ7gHX2IQQgtDZRTU0kKjPuXYmq0fPpnYDWlJjOU2 0mkra2wYB746fkDOzp0Ypsf1yKiUlTxQ4zYtNI67NgVHQzTpctglmxOlJEzzgiMkXZUwdIq cxFTrFrb9Tg0k6C2Q083A== X-UI-Out-Filterresults: notjunk:1; V01:K0:9Zxb4yyw7hA=:xdda5PGOYd8eMgxLqUq5b+ Qnp9f38BH+kdeKwHYiEj42C7mnHJe6vVfzh4beOgkBVGaKtUPMlDBq1DCaHEq+q7lgHDjylzs WWbEjvh9Ij7cnm/taRi+jcyd1K/pJhwyyv3RNhPb52jSQdN6lg9YuKfFPbtmG9ndzcScUaG+Z +NDLv2poiVA22y+n0AaOjb7blo65pPbSi/oBlXoCsdXGkK72suKeJ9AWvKhn+gugmElFaB76A xCRpcVCHm+c52iAA/H3VB5PJPD00l7ex1KdOG9obEnhSf7wcNQ2AZv/dglYA2AHgimWL+fcvN Et7lCxw6fktG2medoD0H8MdqU0LnmtTsvwxEj9qXrVkTT/35BKS0XncvEhh5IbYDQEBi+LMor RJdbDpiMA9GVj+AIeLF0OhHwCf5yNHdYYf6RBy8TyeAVgOCwkuTpWq4o24d7SHunR/kf0onML xdsL9ZCV3WK6NoN6Bol8fWYAK8CLKSxb/sIYk3fJEEz4EJaKfzxEOCcAmKLuAZeQjUL4q1qDv tUOT+Xplkmy5/LULXifLM+0t1k5QJQ5p1IrWUYZg/+zq7Z6he02ml2cnDiBgP7dU9vXgGPLT8 oeiYr9BR1Pk9SXtgOcrrSiZIUgCw7eWsUtqdr9PLzO+dUZYxpycm/wIop/Sy6FmKRPCBvHm7E eCeL3240E8bDFFCc3VCn5hTFmIEhll1njoMO8RSlLDTLFkvPabiBkWk6RnZV/vFcrj5w= Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In btrfs, ASSERT() has no effect if CONFIG_BTRFS_ASSERT is disabled, and gcc notices that this can lead to using an uninitialized variable: fs/btrfs/inode.c: In function 'run_delalloc_range': fs/btrfs/inode.c:1190:18: error: 'cur_end' may be used uninitialized in this function [-Werror=maybe-uninitialized] I assume the condition that the ASSERT checks for is actually correct and we won't get there in practice, but it's easy to modify the function to make it simpler and avoid the condition that the warning is for. Fixes: e5249f75cfd0 ("btrfs: Introduce COMPRESS reserve type to fix false enospc for compression") Signed-off-by: Arnd Bergmann --- fs/btrfs/inode.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index e6f35d923d67..b1d2b38d29aa 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1175,18 +1175,14 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page, clear_extent_bit(&BTRFS_I(inode)->io_tree, start, end, EXTENT_LOCKED, 1, 0, NULL, GFP_NOFS); while (start < end) { + ASSERT(reserve_type == BTRFS_RESERVE_COMPRESS); async_cow = kmalloc(sizeof(*async_cow), GFP_NOFS); BUG_ON(!async_cow); /* -ENOMEM */ async_cow->inode = igrab(inode); async_cow->root = root; async_cow->locked_page = locked_page; async_cow->start = start; - - if (reserve_type == BTRFS_RESERVE_COMPRESS) - cur_end = min(end, start + SZ_512K - 1); - else - ASSERT(0); - + cur_end = min(end, start + SZ_512K - 1); async_cow->end = cur_end; INIT_LIST_HEAD(&async_cow->extents);