From patchwork Thu Mar 23 17:30:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Elfring X-Patchwork-Id: 13185898 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 7406FC6FD1C for ; Thu, 23 Mar 2023 17:31:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 018FE6B0072; Thu, 23 Mar 2023 13:31:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F0C156B0074; Thu, 23 Mar 2023 13:31:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD27C6B0075; Thu, 23 Mar 2023 13:31:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CE22D6B0072 for ; Thu, 23 Mar 2023 13:31:05 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6A3D14076C for ; Thu, 23 Mar 2023 17:31:05 +0000 (UTC) X-FDA: 80600853690.09.EEB13DC Received: from mout.web.de (mout.web.de [217.72.192.78]) by imf22.hostedemail.com (Postfix) with ESMTP id 25646C0007 for ; Thu, 23 Mar 2023 17:31:02 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=web.de header.s=s29768273 header.b=N6z243j6; spf=pass (imf22.hostedemail.com: domain of Markus.Elfring@web.de designates 217.72.192.78 as permitted sender) smtp.mailfrom=Markus.Elfring@web.de; dmarc=pass (policy=none) header.from=web.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679592663; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nO9UAq5syAi4OLMKIu36ONW2Qf6NwtXFql+dlIwQ2Ss=; b=tMgwkkQdOx5Ft1z0dUt1eLjbujtSoJLZcFhJWoHpU5SLHUQYX3jZhyUy53UME6EsbhoSVw w3wn2kPyqYwbEsgIHdR/ohQtpAt7E48z5Ws1nMJ6Le8xuUEhAqC0RNSQ7LtgjMIEBaeL2X +gSPwWc4eVT28KJPQX4n8xgE1L5NcuQ= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=web.de header.s=s29768273 header.b=N6z243j6; spf=pass (imf22.hostedemail.com: domain of Markus.Elfring@web.de designates 217.72.192.78 as permitted sender) smtp.mailfrom=Markus.Elfring@web.de; dmarc=pass (policy=none) header.from=web.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679592663; a=rsa-sha256; cv=none; b=8O3B0lGVnJxcYJI1v8GsI6npKmbJIxEm3WxQsIeBC+8Z3twnRNkTuZ3LDdL4TSK9gtYpUH LAHw9M8vtTIGaKnE2Usk8H62PWVnsn4BE4gOJFnt5gr1sp9uzz9n+Rogx7hGi+/E20ICgf xy7qN6WXzZlEhI8LaLUeVXZVbNxQCFc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1679592657; i=markus.elfring@web.de; bh=nO9UAq5syAi4OLMKIu36ONW2Qf6NwtXFql+dlIwQ2Ss=; h=X-UI-Sender-Class:Date:Subject:From:To:References:Cc:In-Reply-To; b=N6z243j6jC0KmjRhHBXsdR7Q2Ho8OM0s05uwSFI8ivsE5HytvlG1zTbRrrkh7ExwE OYp0wUiggH5yU6Es3HaWPz5haAPmvdJrn6jdOpzJ2WHGYR3BnoTdH9XuzzBTGXbVCW gMr8FwjK+reLVcA9GKj47ORLZEcheZYW59E82VB8/kiBafRAEcOem7iZ2aO4f1JWSm dhlTkuWxzfzWzmgP6m1+tt3IeytTbArDk34wtugohLn+iZSlw7FKqeViJh/x//SQwH E8DPyKHlNq5Sxs3pTtyqublWTwXUTf/ZDTl5TrOQGvxEuKHBeynuvEBgexzueKHDAo nAXDoFw8U+4RA== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.21] ([94.31.81.83]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1Mx0Mr-1qQMYc1sXD-00yNIW; Thu, 23 Mar 2023 18:30:57 +0100 Message-ID: <6e9ca062-939b-af96-c8ff-56ad485d6e79@web.de> Date: Thu, 23 Mar 2023 18:30:48 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: [PATCH] mm/mempolicy: Fix exception handling in shared_policy_replace() From: Markus Elfring To: kernel-janitors@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Kosaki Motohiro , Mel Gorman References: Content-Language: en-GB Cc: cocci@inria.fr, LKML In-Reply-To: X-Provags-ID: V03:K1:Y7W9wGRh0MA8/HaErHl/S2kg9rrrcBU0ZJmC+X2fEGY79dWhCfz Xrek+UdnaBqdZMzalIHev0W9HKB0f12wXiTfTufGJAiA5q5b5WGChSk2iWrYCTPrRjzaBdk iA7tkocD1yXtgLM4lxQOSHvzNQ/DVR5j+gkz2NXGy8CDpISt2YQAPfyQOlTSOPXmMvL8Pep EQQjtpASiD2oXp3/i1s2g== UI-OutboundReport: notjunk:1;M01:P0:kMB+s58VCWY=;qCru+X/jBxqO3w/tT77rw50Jgnk w2DRfMn8GQ18abUS/6CLdF1y0vNs4ucp6xugRZQPxb82Qx6HefowMeHO3uFwTspye/Lb+0Epc JqMsWmk5/Aw/3pn+Bk9Tg6RjH0xogfGM1DT1Hjb4S1/nofKIb02ylddP+3A/Gxntfskg8e8zb m62VMzjKWQ+yzvumu9Bx0+FLXidXxvWptwpvqdwYeaCz6ar5G2ucDFZALvzv3NJmZrBSjdXxL i0qKa4B+VrzuMktGj304QmQuzupfMG0zEc5GfTVqGmYQetDZ99MdhZ+TgOo7N5xeyZjKI0Vii pbCa5aV7guDH9Olqf8GzPlt8/NxsfTIPX00X0q9+1R8UKKN+mbXBAhTppzy79vKMwPtp+CVbW TiMuLo6eXcK7UYer01WynVWcgZffO/DyXobxlZ7KI6Q2GBU+kBB3+Bo99O5EL8BaAFWQCp5Xi s2qyV9ZcchJotEBYut96DXZkEiEJ/qR0boTpgunWMNb3ft9nXLaoVymaCX+8YZDGH53aho3Fi frqEGYPq7JqyopdwFwu6hqoh1NreHnUSXDHBslI+WTHuL9bmMsj06SLtr8DvKdyidj+XVRpLd m8VNqjypJupB+5dHfaM8sKVZEvdKZplVsFqQFFEaXM2xLO7uge3qijRpiTyZS+DgZnG4BBqsW F8Ohri0BDKDCu3aqb6mD0JulpUohiUBLtsErgD61q7/yPXt3cHIP+P4QkTmo5kgJWLQdv82AN 5kj0a7+Pu2jaZ9aAbU6T8cDrSG/crN8C/nvnJaJywiP19GUvksRyFdOnZXXRgYGq7CkKnywSB TEJwuU5r5nzlcFJYerv6SFyqGgjMAFH2bjFww2u3ZlIP9dFUrNz7f0FSDwQnm3FkpgCX455p7 88nuc0dP7p0K+OuCX2Kxl3zJVPQda93X7mMAF5zXyCbn2S1CG1/hfj3UZ X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 25646C0007 X-Stat-Signature: bws8bnni3fokuqz3xfarmotupnpukprf X-Rspam-User: X-HE-Tag: 1679592662-996578 X-HE-Meta: U2FsdGVkX1/oHSL4sh5JD74eypOW33HneCTOw/2vuFlUru5gMBQ7Ofx5NsT62bLD78rZgU0/DcPkQ3wjlYJP8sECKQ3PiiJQuh/bDh+8un7tgfaaArfmtJH9BXCTzM2HztLvtgAqpQK/cIgUNrohCaZm+y9PkGZJwvYLsOVTWeoI/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YQXCvu0Hxk4mmrkXBilzQFrsEE= 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: Date: Thu, 23 Mar 2023 18:18:59 +0100 The label “err_out” was used to jump to another pointer check despite of the detail in the implementation of the function “shared_policy_replace” that it was determined already that a corresponding variable contained a null pointer because of a failed call of the function “kmem_cache_alloc”. 1. Use more appropriate labels instead. 2. The implementation of the function “mpol_put” contains a pointer check    for its single input parameter.    Thus delete a redundant check in the caller. This issue was detected by using the Coccinelle software. Fixes: 42288fe366c4f1ce7522bc9f27d0bc2a81c55264 ("mm: mempolicy: Convert shared_policy mutex to spinlock") Signed-off-by: Markus Elfring ---  mm/mempolicy.c | 11 +++++------  1 file changed, 5 insertions(+), 6 deletions(-) -- 2.40.0 diff --git a/mm/mempolicy.c b/mm/mempolicy.c index a256a241fd1d..fb0485688dcb 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2736,13 +2736,12 @@ static int shared_policy_replace(struct shared_policy *sp, unsigned long start,          sp_insert(sp, new);      write_unlock(&sp->lock);      ret = 0; +put_mpol: +    mpol_put(mpol_new);   -err_out: -    if (mpol_new) -        mpol_put(mpol_new);      if (n_new)          kmem_cache_free(sn_cache, n_new); - +exit:      return ret;    alloc_new: @@ -2750,10 +2749,10 @@ static int shared_policy_replace(struct shared_policy *sp, unsigned long start,      ret = -ENOMEM;      n_new = kmem_cache_alloc(sn_cache, GFP_KERNEL);      if (!n_new) -        goto err_out; +        goto exit;      mpol_new = kmem_cache_alloc(policy_cache, GFP_KERNEL);      if (!mpol_new) -        goto err_out; +        goto put_mpol;      atomic_set(&mpol_new->refcnt, 1);      goto restart;  }