From patchwork Mon Oct 24 20:57:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 101613 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp2782603qge; Mon, 24 Oct 2016 13:57:59 -0700 (PDT) X-Received: by 10.98.57.84 with SMTP id g81mr31979053pfa.115.1477342679741; Mon, 24 Oct 2016 13:57:59 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s17si17249377pgh.144.2016.10.24.13.57.59; Mon, 24 Oct 2016 13:57:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965670AbcJXU5z (ORCPT + 27 others); Mon, 24 Oct 2016 16:57:55 -0400 Received: from mout.kundenserver.de ([212.227.126.130]:56655 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965393AbcJXU5x (ORCPT ); Mon, 24 Oct 2016 16:57:53 -0400 Received: from wuerfel.lan. ([78.43.20.153]) by mrelayeu.kundenserver.de (mreue005) with ESMTPA (Nemesis) id 0MTKuR-1cNhA70R8B-00SMQY; Mon, 24 Oct 2016 22:57:36 +0200 From: Arnd Bergmann To: Hugh Dickins Cc: Arnd Bergmann , Andrew Morton , Al Viro , "Kirill A. Shutemov" , Michal Hocko , Andreas Gruenbacher , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] shmem: avoid maybe-uninitialized warning Date: Mon, 24 Oct 2016 22:57:09 +0200 Message-Id: <20161024205725.786455-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 MIME-Version: 1.0 X-Provags-ID: V03:K0:PNHGG7WlWAjzJ3zrkZNCy4vXvIbUn61eKY+0qDHwg6WVdku8jUJ Ii/7DctrryGnqoFkk9jiy3bYZPKa7jRPlSfg+TWfghCWusOEabvE0Ql/UlGGf91x961KUWj 36t58sWc8mN95jJzzkZ043IK2SC7quuo+KrCAL14Y3YIk6BlExpUdlsto/U4ys7tEIE1nFk 1pwiuHHdda28Gelhot/xQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:inNpqckm1JU=:icnFtSlnX+c48ZYSLy4Bn1 14NUt4JMdp+NX7MTTkeUbgJyPDwmTXAsjJ7qHURu+72l8w5X1HW4iPNYdpwnCd4c9yIQsvMIm cNld+XnOaLv/2uBnryEUalTfsdXOOTPqPbacLNcjG+fUImYek1wa7Rd0C4yRcqgmf8uK4O61a J6OMbLqn0rscgAhliGkpg+lLd22VbjVm8E6s8zS8kUnogzJyWA7envnjeiCWR1v1rrJyOrb5F vAG/j2eNGi5ulh8CEirx+mo3T5V5qOCuMglxnlEcu3xrUJvvYRQ8UkdzKhUuStsBMS9COMxW1 R5YILjxtZguStjHY3Qms48lvnP/iz5icOYjn5TrCPn4vC1v2h5HL+bfC+B7Z/dHfikcaln5WE JT9DnbDUwv6uWgX/0xV7f5BXkMtmE/oL8ilIZuRDk6vCVd4DrwBvXqZOQitHUALMapItXgq9r hTpFKHwGApv19O4j+bs3ttIajaapzyMNPU7q3HBgAXw26Fx9HX7mcMvlK2tuq3XExtHG8BblD 1covxVVm5zntmlkpxuwCJhbLdIiAZy4U3McfqyvljtLItdtvd5IWYTv5Xhfhx+rzQi++I5BY8 ypkFq7XH5HMwHfmUzk8Xl2nb2LcfVoB/MHgecKXSvN535qmqPuIIVVOiiBSGLrWmFDxOzVoGk dgjG22HtxvbcK50MDYcR6VtbRcaYDHZLlspvdhYxR3mTRfEOvz1TSJY3wmn7/fPnBvzJw4UZm MeLx0+DMAxFEkGpl Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After enabling -Wmaybe-uninitialized warnings, we get a false-postive warning for shmem: mm/shmem.c: In function ‘shmem_getpage_gfp’: include/linux/spinlock.h:332:21: error: ‘info’ may be used uninitialized in this function [-Werror=maybe-uninitialized] This can be easily avoided, since the correct 'info' pointer is known at the time we first enter the function, so we can simply move the initialization up. Moving it before the first label avoids the warning and lets us remove two later initializations. Note that the function is so hard to read that it not only confuses the compiler, but also most readers and without this patch it could\ easily break if one of the 'goto's changed. Link: https://www.spinics.net/lists/kernel/msg2368133.html Acked-by: Michal Hocko Signed-off-by: Arnd Bergmann --- mm/shmem.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) -- 2.9.0 diff --git a/mm/shmem.c b/mm/shmem.c index ad7813d73ea7..95c4bb690f98 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1537,7 +1537,7 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, struct mm_struct *fault_mm, int *fault_type) { struct address_space *mapping = inode->i_mapping; - struct shmem_inode_info *info; + struct shmem_inode_info *info = SHMEM_I(inode); struct shmem_sb_info *sbinfo; struct mm_struct *charge_mm; struct mem_cgroup *memcg; @@ -1587,7 +1587,6 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, * Fast cache lookup did not find it: * bring it back from swap or allocate. */ - info = SHMEM_I(inode); sbinfo = SHMEM_SB(inode->i_sb); charge_mm = fault_mm ? : current->mm; @@ -1835,7 +1834,6 @@ alloc_nohuge: page = shmem_alloc_and_acct_page(gfp, info, sbinfo, put_page(page); } if (error == -ENOSPC && !once++) { - info = SHMEM_I(inode); spin_lock_irq(&info->lock); shmem_recalc_inode(inode); spin_unlock_irq(&info->lock);