From patchwork Wed May 4 13:21:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 12837944 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6163C433EF for ; Wed, 4 May 2022 13:21:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4EFD66B0073; Wed, 4 May 2022 09:21:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 49EF56B0074; Wed, 4 May 2022 09:21:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33FDA6B0075; Wed, 4 May 2022 09:21:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 1FD2C6B0073 for ; Wed, 4 May 2022 09:21:39 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EB219A50 for ; Wed, 4 May 2022 13:21:38 +0000 (UTC) X-FDA: 79428122676.10.110DD76 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by imf22.hostedemail.com (Postfix) with ESMTP id 3F4C6C0086 for ; Wed, 4 May 2022 13:21:37 +0000 (UTC) Received: by mail-wm1-f46.google.com with SMTP id p7-20020a05600c358700b00393e80c59daso2635115wmq.0 for ; Wed, 04 May 2022 06:21:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bIzJlgmOg9YiKbOpYW/F57m78adXKAVkRe+KXRci2bg=; b=j3V/s2IRf9hFGeuzK9juEkMCXHJ1cbZDrP7Ql2RiQJeM8R0ebx1Yr8EC7SHGJNp13J JfwmCunK/UWZdcN1W6CibqOX9t1P6GPh9LbrYQzvMO8HpQZqJ/ZdTXMs5wOd4353Q7+5 5w/AqtUqsoEgevgEh6zxncr0OMzKE1wBm+HoWj6XU82kYnvMIOaCHpTWx8pWs4+rW5pV Jn4oaGewWU51/7QX0FtxVGnTfxqfhHd5eGaJE4NUSGA9Gm+J7/tifdqBSxlNDzT+DFUC uYBvMfRM8UMxg8qaTexzL3Sj+Tv2eh0XXfq1SAbHJld0IjuMMYjb6799gDAKZkiv7LMz b6qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bIzJlgmOg9YiKbOpYW/F57m78adXKAVkRe+KXRci2bg=; b=paUuI10iMGFAK8MQgxijpf5putHlGu5nmjR+CVo6/3pf0EFcvBQWA25QOEkWoMbK1f VryUay+JycPpNvixQHGCnkep35UzxF6vGDnxwZ3GAGUVVy66ZIKQHu9CARZXpJebN1x6 8rCl3pdh/ceg3sCko4LXIRH/5y6KczRmq8h5+2/axj5pS/3hXOz+uUf5etc1XO4QVUeA /2H7YYaP5QLBFpkhK1syRcFMg/XVMiFNa6gO57XVqb5fh8LWf2Gb28cwEGh9qIydmXf2 Iy+tP3yx1mX2ZARSPVjWKIvpL3d585ffUdjyg7Lns1RxgDrkWfXSRs83NgKIQsa3iSVF WpFQ== X-Gm-Message-State: AOAM530Ssxw8O1rq9q3mjM2JQLaKmoYJZNDdrv2KSQxRvMlmjAZv0TxT 0jKoCwyIPIutk2Uxh7I4Ft4= X-Google-Smtp-Source: ABdhPJzJN6G23D8uMob63DnbbeBf1pop4Zafvwcca/FweJhoFEf7s5Blf1jwse+83kfTgVRfuwAysw== X-Received: by 2002:a7b:c186:0:b0:394:bed:e0cf with SMTP id y6-20020a7bc186000000b003940bede0cfmr7578863wmi.162.1651670497066; Wed, 04 May 2022 06:21:37 -0700 (PDT) Received: from localhost (cpc154979-craw9-2-0-cust193.16-3.cable.virginm.net. [80.193.200.194]) by smtp.gmail.com with ESMTPSA id f8-20020a7bc8c8000000b00394615cf468sm369401wml.28.2022.05.04.06.21.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 06:21:36 -0700 (PDT) From: Colin Ian King To: Hugh Dickins , Andrew Morton , Matthew Wilcox , linux-mm@kvack.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH][next] mm/shmem: Fix check on uninitialized pointer 'folio' Date: Wed, 4 May 2022 14:21:35 +0100 Message-Id: <20220504132135.229601-1-colin.i.king@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="j3V/s2IR"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of colin.i.king@gmail.com designates 209.85.128.46 as permitted sender) smtp.mailfrom=colin.i.king@gmail.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3F4C6C0086 X-Rspam-User: X-Stat-Signature: 5iwitt7miuj4wr9ghqsy11xw1dszs6gw X-HE-Tag: 1651670497-535308 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In the case where shmem_swapin returns null, the jump to the error return path via label 'failed' will end up with the uninitialized pointer folio being null checked a few statements later. Fix this by ensuring folio is initialized to null. Detected by clang scan: mm/shmem.c:1704:7: warning: variable 'folio' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] Fixes: 2b58b3f33ba2 ("mm/shmem: convert shmem_swapin_page() to shmem_swapin_folio()") Signed-off-by: Colin Ian King --- mm/shmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 107f1e4dd0aa..7faaa61ff7fa 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1682,7 +1682,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, struct shmem_inode_info *info = SHMEM_I(inode); struct mm_struct *charge_mm = vma ? vma->vm_mm : NULL; struct page *page; - struct folio *folio; + struct folio *folio = NULL; swp_entry_t swap; int error;