From patchwork Tue Mar 21 10:33:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Elfring X-Patchwork-Id: 1759384 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=112.213.38.117; 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=A89V0Kgn; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4Pgp0V1c67z247k for ; Tue, 21 Mar 2023 21:35:38 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Pgp0V0RXLz3cMs for ; Tue, 21 Mar 2023 21:35:38 +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=A89V0Kgn; 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=82.165.159.45; helo=mout-xforward.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=A89V0Kgn; dkim-atps=neutral Received: from mout-xforward.web.de (mout-xforward.web.de [82.165.159.45]) (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 4Pgp070YQNz2yPD for ; Tue, 21 Mar 2023 21:35:18 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1679394837; i=markus.elfring@web.de; bh=vndjNXkPmTxF0BPBkraC9oszufUtdq4WgZMkzAOxXDo=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=A89V0KgngrmZZofv5QrNSfXK25TfNFNj5/6zVZYhKdHjLIg60vGUb7l+RQAWmykpt 8cN4Rh9/xL94Z6rlGmvffTUf5gfsR1JV9Mu+0VrVuPpezQki1W2ye7XsCRmuFW6fv8 znG1oYQIS7Kk9EW9SRAa18mb2WLrJ3tpX83H2i9vDkhJ9rhLedEFB1ie8bfZ22aeZw /c+IwI+Oymj+RNM1rX8OlslC95M84pXnbgIq0I8hzx4ZMutgx9HZAN7gO9sqfncPSt PE957TZlPqPD+Rz9FWE6kESBJLJgb0AbOXrgGgkAB4fa/1bHlNLIopwvn34JpABSPR WlUdSGEqzJeGg== 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 1MnX5T-1qNIGW3LUb-00jO3m; Tue, 21 Mar 2023 11:33:57 +0100 Message-ID: <8949eefb-30d3-3c51-4f03-4a3c6f1b15dc@web.de> Date: Tue, 21 Mar 2023 11:33:56 +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 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> In-Reply-To: X-Provags-ID: V03:K1:cUS+tA463HYUlb/iUpPOArqy6VeUFp3JFsh/x1olBn4hTXcKng3 vXYjvYRNl5OrT5wPkTpA5S7RFY1GKu/TSn7FBzeOL8e639SR2iaaWB3Fb2x4HC2u89sjsf6 miv3T206bbdiH2QQpC5bBzSYFyDp1qTdKZwJggwZhGdb9x5SxBQl9UVlTaPJf8wqG42/JQV 2BqvRnNJ7sz0FRY++A4qQ== X-Spam-Flag: YES UI-OutboundReport: junk:10;M01:P0:Gr2jsBBO1Go=;liunclFFJopIqm5hKq6VgGlpa4tMs m/0CGPlgoSqPq4w4vbvfkPANp3Pb7FoaVcpTNlMm5dGWlurf8Tl4P3GzOGhQBeTm8dLPoLDh/ atFnBFHMn9ba9S/S59/tlT1s4AdXmgL4P0GKDETiwW2T106q0QqlvmikTOjkV6+M071TttNDF 1njSj4O7HZbL77vzuF2zblNA0+AtY9mYIOY0SWSpddXqtjVmZIoG6hRsK9tO1KuxZKqKAjhwp vQaxGXSpyabe27seFiE1kyvKWjat9PNO3vYgmPbBTJYbWrqmtuIpNBCMw6fN5JHhNbP7WNUMt LYawuT3AOCJLhP1i2X8c8T7Uiu3oV96XjHZbzPFbz6ikv90QquRvo/hQ6S/RGArXNfJDeztY/ 81onrXM9SWgGvSLmKaSLDCWvr1UTWoMCX2ifNYFcMxx1hxHplWQkHxyHTXkOloqF0QEXw1YYB MAHMh7gyBJD+xT1WO/xNM8Rzn+LyCDlH84wPjBDnGmlrNV7jy+YB68efJcmPE3n6qWFf8aDI/ tCknHbsyLlYzLoYtbQ5o/CQtaV6RpJAbUwWUy2Jni6FhLDVUSnBtcJbm+ZJ0s0t59wLVqzyu6 p9syNUdjH2aUim/YTcqIdgy/P6qLRpDDKlehdJeqrTS5Fm2if+1bWcBrdo0Pw4WlImWzuAZFn /GXxZakCedLq47Vr6ruwmhwVA8orKN2mDRFKrPjRZJdtPFWFfk6YvR8PMnJ5REPHj1LkssUwe VLG/tWUY5rsJaRCTW7lq5DC5NY2RzWEvgztx5NznJ/r9yTZVod3wPhZzEA7KcaTeNhz33lcYH K2Hz1FOiEmPj5bEYnGvMD7BcVMfGt9QAxAxtqAMpbiSR1R+Kf+j/4AQkJwsYn1GJ2jUx+UiPe M8DAytK5pELoT9x9aHTqqcTDmE5sIW6DsPLr8+6tqpNmP6JQ7zSIshh2Hoyw6Bpzt53HjV8oM Hm3l/YtdEdlOjL+wkkB9Z4XDVhPB/5J8w5soo/neI4bako5HkW2PJj2WotvusxaNmPhpgDnFu M2I4zvmU9+xY7OwM= 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 Tue Mar 21 10:36:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Elfring X-Patchwork-Id: 1759385 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=dfz0zp6k; 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 4Pgp2b5Rsgz247k for ; Tue, 21 Mar 2023 21:37:27 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Pgp2b4Fbyz3cd6 for ; Tue, 21 Mar 2023 21:37:27 +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=dfz0zp6k; 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=82.165.159.35; helo=mout-xforward.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=dfz0zp6k; dkim-atps=neutral Received: from mout-xforward.web.de (mout-xforward.web.de [82.165.159.35]) (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 4Pgp2G2Pzkz2yPD for ; Tue, 21 Mar 2023 21:37:09 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1679395005; i=markus.elfring@web.de; bh=BIc+PISjxVPBc55dVATLly0k5R8zHbZLDGw/LWHdgf8=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=dfz0zp6krx+HoOSz7F1rfYLCpZTHHaC7lDA3Jz2vgPqqtICIqSP6b3oo1FgqfFae7 ZpMptq4ZLbCFOj5LZd2x92d+L+l7vxaKiyLtw8rhGolAARCdgqL1lFxKj7hKkbwh6v Uw6GYi4DMP2ycsaBXAt/lvPVQNcd2D9Cy/z6sEulXmIQ7HhCgQTaIr4EEztkxeeQsy rSe0G7MfdXxoexhxSEDO+r5+w8d0fE2Ahxsaa707BOpTq0jpxi5rj/pNleJHblra03 vvdW+P2gh70ivHz3DJSWP6LtWvDZN6+PgrF3r+OnFkxV3GcUMvETHxgR/iMssirAjt GpMJXILcuP50Q== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.21] ([94.31.81.83]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MumJF-1qVZiZ4AFP-00rr2m; Tue, 21 Mar 2023 11:36:45 +0100 Message-ID: Date: Tue, 21 Mar 2023 11:36:43 +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 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> In-Reply-To: X-Provags-ID: V03:K1:nyp/+9Cx269IjOVyB3aeJBjyVAjpww9ps+sIKWMCzGEvmhY1V09 72ZdbXxsX1BJs9FIoo2LKijY04Kh/qN7K3wsuxnJOFLhGDxEhM2sI9lXSjpwR1bOknL4aX/ xTsUU6kT8uthSOjksmIv9RgWMBPiZMB1wGo6Ni4IdQR4qwnDVOkVBSkmKaW4PwrYKYgbPtX zJ8QKDaFzjsrvxiNbQn7w== X-Spam-Flag: YES UI-OutboundReport: junk:10;M01:P0:MQApYcTHWzo=;kyFUCZrqQ//ZeA3kaps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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;  }