From patchwork Sat Mar 25 13:42:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Elfring X-Patchwork-Id: 1761139 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=web.de header.i=markus.elfring@web.de header.a=rsa-sha256 header.s=s29768273 header.b=F+3KSBJY; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PkKz31Z8dz1yY7 for ; Sun, 26 Mar 2023 00:43:11 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4PkKz26cW6z3cgR for ; Sun, 26 Mar 2023 00:43:10 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=web.de header.i=markus.elfring@web.de header.a=rsa-sha256 header.s=s29768273 header.b=F+3KSBJY; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=web.de (client-ip=212.227.15.4; helo=mout.web.de; envelope-from=markus.elfring@web.de; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=web.de header.i=markus.elfring@web.de header.a=rsa-sha256 header.s=s29768273 header.b=F+3KSBJY; dkim-atps=neutral Received: from mout.web.de (mout.web.de [212.227.15.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4PkKyg74bzz3cLx for ; Sun, 26 Mar 2023 00:42:51 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1679751755; i=markus.elfring@web.de; bh=KO3BKZVVw6mbo81Zr5Lz6Z01ExV290PntqJFfRRjrKU=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=F+3KSBJYMSP5pb4y/6UgRtIeNH5oU5uU89AJtNbxlZvBYPFTgMh9MIucGfXrWy4gh ISqTOWmtKiBccT5RqtjhosnUuFdrQlC6qPgQM3uNsPLNzYgtLnApk7h2uO/2Y91uke R6NdLenHGCHVHkCrkSG5E2/GBp2UJ2NiNDKktJgqaUKb4uElmQrIpiCpJCcDntHv/h PM/GcNRbxEd4SeuklaF2ZeIS+H04oXU1xT3NUjwHddnjkffFHTnrWvPYpPRNfd1FpZ a6pNMVg3oZhUzazokWy9m8faPfw1MAUCab4aZmUnlhSHjyhKfTAsvP3ztIYGBAund3 K5xFlXxLilYkQ== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.21] ([94.31.81.83]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MgibY-1q7PEd2jSm-00h3HU; Sat, 25 Mar 2023 14:42:35 +0100 Message-ID: Date: Sat, 25 Mar 2023 14:42:34 +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 resent v2 1/2] powerpc/pseries: Do not pass an error pointer to of_node_put() in pSeries_reconfig_add_node() Content-Language: en-GB From: Markus Elfring To: kernel-janitors@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Christophe Leroy , Michael Ellerman , Nathan Lynch , Nicholas Piggin , Paul Moore References: <0981dc33-95d0-4a1b-51d9-168907da99e6@web.de> <871qln8quw.fsf@linux.ibm.com> <87v8iz75ck.fsf@linux.ibm.com> <2f5a00f6-f3fb-9f00-676a-acdcbef90c6c@web.de> <87pm9377qt.fsf@linux.ibm.com> <08ddf274-b9a3-a702-dd1b-2c11b316ac5f@web.de> In-Reply-To: <08ddf274-b9a3-a702-dd1b-2c11b316ac5f@web.de> X-Provags-ID: V03:K1:RfdaZlFOSV3M64SKFPUXdwaCJTA7xUu4N6/KaHtpNrcYpQ2mw1y ePwYGxPOYKd4LLfoQcjSJppIa2nvji/228ZpC2qOmUJFp2LtM8GkopMUPRggW5tJq6M3uYT 1JbDjxgYSWVncu3ciDR6U96LOafJvToRGG8e26OFOEKpHxNMzD8vtCNToKHDiMkAWnRpXSN DWRuqpQno3pgFXBCi/aww== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:euUHpvkGFEs=;yVylM0wy3kOod/nSXvMQmTXuEV4 inKf53S6H+hxB+Gk3HT/DYa7hHeyKRvf30mnJX8iz/w4JCHlD0dVPZMtfSkz322fHhRRc7niU x3jFXG6q9ocHgp64EPZ1QGkjyuLA169TDP6Ih+z5a/QaQ54ncYwlLOp3I0JdFx5Us7PMLB9Bx 5rWkbPZUlOcptjNgMGEXkJAu+PxI7JG619D9UzTqHIT27GWQKzBgh/zk6NkGa2RSd8URbHFgw IGj9TpatrH2CJoY5wHIFZLy9+PfJuYVelhvgB6N2u4oBmoekXiMKQfxsfUy93fpin7nZJheGo 3ZS4q/kuurX4FSuSK+RoHv2rD+UwZX2H6YiBKfEyN4Cj3DisU4rhhAsu1/Y0f75fyFHjxpdcq hkb1zUDnpUUW/A+bQkKo36GHQGLI+Hr8gZFtWBMaLtaAIQ1PrRBgPRI6WU2ZvIyeeOWvBak6V XJxnlXsOW/8Hx2OtlicmHmOFXEtLCW7OHRRMxZu/dOnFbxJ688VatBTyXqoKu7Sf1zfmTCg7W lL79T7aYfwegoZW1J62GNUDe/RauWPohNCa4Fhxdmt9smUJ55/r8bm1jHH6enfEp8vVafZ0Kf nr9EfL888lMCOqBcQuMtJB6mvd3CelAiCIpeePdY6vv4FMzhdDeXCHDfRytACilNXraDqp6O6 Ab4i8w8rMBQQXYIaScxK0u1wa7z/VZoeswLlxSLxJdNWPsdFMLQD9dXxua6Uo2WMAwC98+HtO 14UX8gQnuosefZV3elSFrFUxrb03vxSFh4HNODX6hKhp7yyDrKnnIdKv/qgbRc7gxbtqLe7pt KwrnsqRNyt7L0wBcWzXbtAgRWgkvO1LJmjBQR4jv2jPK1BjUhVF9bKcpjGJida0PTSJ6EHpay 0ba4wsPDhZ97cPG5hCZEo898B0Z1l5uQHjuOfLhWZyXBQoKc04N0cjRnc X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: LKML , cocci@inria.fr Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Date: Tue, 21 Mar 2023 10:30:23 +0100 It can be determined in the implementation of the function “pSeries_reconfig_add_node” that an error code would occasionally be provided by a call of a function like pseries_of_derive_parent(). This error indication was passed to an of_node_put() call according to an attempt for exception handling so far. Thus fix the risk for undesirable software behaviour by using an additional label for this error case. Link: https://lists.ozlabs.org/pipermail/linuxppc-dev/2023-March/256025.html Link: https://lore.kernel.org/lkml/87pm9377qt.fsf@linux.ibm.com/ Reported-by: Nathan Lynch Fixes: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 ("Linux-2.6.12-rc2") Signed-off-by: Markus Elfring --- V2: This update step was added according to another change request. arch/powerpc/platforms/pseries/reconfig.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.40.0 diff --git a/arch/powerpc/platforms/pseries/reconfig.c b/arch/powerpc/platforms/pseries/reconfig.c index 599bd2c78514..44f8ebc2ec0d 100644 --- a/arch/powerpc/platforms/pseries/reconfig.c +++ b/arch/powerpc/platforms/pseries/reconfig.c @@ -40,7 +40,7 @@ static int pSeries_reconfig_add_node(const char *path, struct property *proplist np->parent = pseries_of_derive_parent(path); if (IS_ERR(np->parent)) { err = PTR_ERR(np->parent); - goto out_err; + goto free_name; } err = of_attach_node(np); @@ -56,6 +56,7 @@ static int pSeries_reconfig_add_node(const char *path, struct property *proplist out_err: if (np) { of_node_put(np->parent); +free_name: kfree(np->full_name); kfree(np); } From patchwork Sat Mar 25 13:44:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Elfring X-Patchwork-Id: 1761142 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=web.de header.i=markus.elfring@web.de header.a=rsa-sha256 header.s=s29768273 header.b=cT3A7uc5; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PkL1B3XKrz1yY7 for ; Sun, 26 Mar 2023 00:45:02 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4PkL196z6Gz3fVN for ; Sun, 26 Mar 2023 00:45:01 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=web.de header.i=markus.elfring@web.de header.a=rsa-sha256 header.s=s29768273 header.b=cT3A7uc5; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=web.de (client-ip=212.227.15.3; helo=mout.web.de; envelope-from=markus.elfring@web.de; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=web.de header.i=markus.elfring@web.de header.a=rsa-sha256 header.s=s29768273 header.b=cT3A7uc5; dkim-atps=neutral Received: from mout.web.de (mout.web.de [212.227.15.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4PkL0q1lncz3cM3 for ; Sun, 26 Mar 2023 00:44:42 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1679751868; i=markus.elfring@web.de; bh=9MEMV3HONXkOFdWmD1JKhyX20q5i9cTWfln64sH0OnM=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=cT3A7uc5KNtpT3Ndr0DpZhZmxgz02TyJ68nuD1VYOzF5hqehYYxGDIOW12+Raea2D zyAxGfFTwaW1P8Xva8QvXJE77EaLnjEd8ARJaYX4kU2sFjaW9UNxvUTAoeYjytLvjp ecftofcOSlhZiFWYj37ngPIbOFrL7wdb7MwYUfoidFu2dayG+aVeb5iN+Kioh7CmxU Xp9fBuOPFnlM0SGJN4ExMRtbcjTntXLRycTRgbFMB25Ib/y4zGx9eHyYDMkQnbjirK TqkkjmYnxBr9mtstzwH33bCqRKREeLmkM0lMwjq0ZGvuB3FN/G6AdV/hclZrJjac/l KMuQIdTWHo8KQ== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.21] ([94.31.81.83]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MhWop-1qAQvf246V-00eYGf; Sat, 25 Mar 2023 14:44:28 +0100 Message-ID: Date: Sat, 25 Mar 2023 14:44:27 +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 resent v2 2/2] powerpc/pseries: Fix exception handling in pSeries_reconfig_add_node() Content-Language: en-GB From: Markus Elfring To: kernel-janitors@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Christophe Leroy , Michael Ellerman , Nathan Lynch , Nicholas Piggin , Paul Moore References: <0981dc33-95d0-4a1b-51d9-168907da99e6@web.de> <871qln8quw.fsf@linux.ibm.com> <87v8iz75ck.fsf@linux.ibm.com> <2f5a00f6-f3fb-9f00-676a-acdcbef90c6c@web.de> <87pm9377qt.fsf@linux.ibm.com> <08ddf274-b9a3-a702-dd1b-2c11b316ac5f@web.de> In-Reply-To: <08ddf274-b9a3-a702-dd1b-2c11b316ac5f@web.de> X-Provags-ID: V03:K1:JoEdPDWmvgdeSdF982ek9rSr9udo+HdUu5DiQjjaQjTjG+v4jf/ eyv2L9JJ+4HRvl5WUJmKLUzQsYQri5K+5uWHa/LTB8X417ZMtSh/kQvFTMOYLhcgwyU6MQm ow9BgWmLEmhs/TuY9ZWlc0Vafzd4B9zRALz9Y2rAqKwrbB6wEwCpoIX8Fcs2KUlgJaZUSrr NwCHGzZ17BoLOYvT0aUIg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:PXV7EA2zsIc=;S7bNfX5q2cCpl7RnOrCc42eGJs9 b50zOCwALGHAJKTbK2cFrj/O4Jp0gKlBHfjWIuIZ5ZezUA7ynYY2Y3zFnBrZMpiVcVghjbaWD Sf+NAF/nmPwUA+CAzxKQDbZIsW39FhZTpnmL0XDtHuX8g3W22QBl/fO0qfCQa97DkjawxiudM Q/KklQZMsgip6ZGy2wraEKJY7IS3QaEObijmB8fdwEILC5gZAMNWODX2f+KCKU+MdlKvNlsk3 cwXMHF5/6o+/CgdrSERbsd79Y85LLkp+C+wce0j/j5xqC9DrXo7giOP0bG5zGhfZnZ0XMbglW /36VD2E0rN+COGJYBxuu6kRe+YXuRW32GDNTPNNBd1EJE3M01YeetF4BGAl1MP9scebcrl4T6 9xaqvsSvGZPKx+RVm1aKBC0NME/yARSLsoNkWuXrPN9qpgMo0SSGv6mHszd7V1OvtM3dKfZUN 3gwd5QtP08n/LdLM/65XQigNhQpZvFJgoQ+/SOFyb524vPSRaWiokJYFhTMADgq8BCrO2gyj2 7z2WNp9EC/ckWcVaZfMDw1i/M8ZB4/H1xyQGghL79RJK1wokOt5O02Y25AXhRI2rgh8LVlkFe 4G+o3K+A3gICmzqsyyQaFCsV0awQNdv6TcAwOMYkwtqNl875rv3dEqx5imTPg9lwv43Y5+4WT kM2dR07eRo3t20Wd0FvVQvcujB456sRVWj42XlMJU4d+8nZ/Thh9JymqgSxUIkEwFi8hufigK nplv/fhR7C2d+2y0jCLhXDeiGvg+Ldop5qgjgunaYCKyxgsruEYY9skXyFkaw08x9D/E/+urP z6i863Uu3JmrcZKlDMWw0VyUCPZr0ob5Cbva0YgjzgbiwU4IAq4KkjtBmKdFwMo/HVk4tA1r7 P5iKVI5aO2RQtn9TibzgauzLpWz0kJ1ZAXoBFZq8g1BDAdJ2550s9570t X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: LKML , cocci@inria.fr Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Date: Tue, 21 Mar 2023 10:50:08 +0100 The label “out_err” was used to jump to another pointer check despite of the detail in the implementation of the function “pSeries_reconfig_add_node” that it was determined already that the corresponding variable contained a null pointer (because of a failed function call in two cases). 1. Thus return directly after a call of the function “kzalloc” failed. 2. Use more appropriate labels instead. 3. Delete a redundant check. 4. Omit an explicit initialisation for the local variable “err”. This issue was detected by using the Coccinelle software. Fixes: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 ("Linux-2.6.12-rc2") Signed-off-by: Markus Elfring --- V2: This update step was based on a previous change. arch/powerpc/platforms/pseries/reconfig.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) -- 2.40.0 diff --git a/arch/powerpc/platforms/pseries/reconfig.c b/arch/powerpc/platforms/pseries/reconfig.c index 44f8ebc2ec0d..14154f48ef63 100644 --- a/arch/powerpc/platforms/pseries/reconfig.c +++ b/arch/powerpc/platforms/pseries/reconfig.c @@ -23,15 +23,17 @@ static int pSeries_reconfig_add_node(const char *path, struct property *proplist) { struct device_node *np; - int err = -ENOMEM; + int err; np = kzalloc(sizeof(*np), GFP_KERNEL); if (!np) - goto out_err; + return -ENOMEM; np->full_name = kstrdup(kbasename(path), GFP_KERNEL); - if (!np->full_name) - goto out_err; + if (!np->full_name) { + err = -ENOMEM; + goto free_device_node; + } np->properties = proplist; of_node_set_flag(np, OF_DYNAMIC); @@ -46,20 +48,19 @@ static int pSeries_reconfig_add_node(const char *path, struct property *proplist err = of_attach_node(np); if (err) { printk(KERN_ERR "Failed to add device node %s\n", path); - goto out_err; + goto put_node; } of_node_put(np->parent); return 0; -out_err: - if (np) { - of_node_put(np->parent); +put_node: + of_node_put(np->parent); free_name: - kfree(np->full_name); - kfree(np); - } + kfree(np->full_name); +free_device_node: + kfree(np); return err; }