From patchwork Tue Jan 23 17:38:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Elfring X-Patchwork-Id: 765792 Received: from mout.web.de (mout.web.de [212.227.15.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 774467F7EF; Tue, 23 Jan 2024 17:39:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706031557; cv=none; b=GcPzWcdGmbMdUO5IrX2JFg54AWcGXLwEaTyu1aJ/9fPygVP3onTG8GnvhZWUKFHdf/GzxIaTB1qVQC5+Xw+5ciGTKLWfefNaqOaOK3wmR9HTCk+UbTqBd35SATLBxBUArUHxbVMjRRtKKJul464m5CyWdsr9gd1ihPL1xENy2pk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706031557; c=relaxed/simple; bh=j1oHpg4MxoWTUcQaZ1olHovNZwz63l8U9f6+pGJ2lyw=; h=Message-ID:Date:MIME-Version:To:Cc:From:Subject:Content-Type; b=NdK73ik1GvOADi5RSSKAMoYJ8ehF/vkoo9IiMvY/KIBquoc6sylWbWreqBSohaPhp5QdoyhIw7xMp51a2+1E4Jvq6YSdKyyU0jFXvnT3lkZ+gJ9ifT/sLz/ImbeGYc+dXTd0etHczQAyyDgOAL7PBhfKO0PxN2ntAARe+5L/AVQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de; spf=pass smtp.mailfrom=web.de; dkim=pass (2048-bit key) header.d=web.de header.i=markus.elfring@web.de header.b=Nw2HZd/L; arc=none smtp.client-ip=212.227.15.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=markus.elfring@web.de header.b="Nw2HZd/L" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1706031525; x=1706636325; i=markus.elfring@web.de; bh=j1oHpg4MxoWTUcQaZ1olHovNZwz63l8U9f6+pGJ2lyw=; h=X-UI-Sender-Class:Date:To:Cc:From:Subject; b=Nw2HZd/LI3K4FI7m1djjISxf6D2R8AsLKI2IdRYiLQjaQOz+0+3ICR2TYjGwhbpk ZPhTPvKYLyAC/nqzMkkSjEd3bevz2F14muq0IeWoO8OFuPJ3yg+QJBbbjxCwLCAok +aJKbbhiPJqcvS9QTe8Vi6NZRxgiooUInYhg8X5hgZ/ckHuXCNCLVTBQSOmH3dfEY SRAh3GMLyLOXEs2scYvc+2rJTWPtizR88Csme1ig260izjVHz4swSiGfyOySMgTrv LHxMTt6kcr21wcIg/O2QZ3VSToEPm9jSuv67uOr0fCRUfLTkSCi46CqbNNEG+4Bvh LbItnEetlFd21npPdw== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.21] ([94.31.87.95]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1N01Za-1rDGct0iwQ-00xLW8; Tue, 23 Jan 2024 18:38:45 +0100 Message-ID: <0b2bccfb-d1a3-4c2e-b1d3-159630edf21a@web.de> Date: Tue, 23 Jan 2024 18:38:42 +0100 Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: devicetree@vger.kernel.org, kernel-janitors@vger.kernel.org, Frank Rowand , Lizhi Hou , Rob Herring Content-Language: en-GB Cc: LKML , Kunwu Chan From: Markus Elfring Subject: [PATCH] of: unittest: Return directly after a failed kasprintf() call in of_unittest_pci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a7fPNm2KMdBtubmTl1bF0Y0ugGehfxFTIi7X HoxfK6ZmcUrLIukBKhFvdKVJu6KDKWR1UuHjNORT0GeoF+BEtGa7En5KNJs0rv9+mQQAJT+Gk XqFzjn8Tx4FtDORsSn+CLBmEUGas1RZlOCyLcGJh0Pp+KxXahOp4pOzMEfP2xZKpAZChlg1ir cflSnA== From: Markus Elfring Date: Tue, 23 Jan 2024 18:24:53 +0100 The result from a call of the function “kasprintf” was passed to a subsequent function call without checking for a null pointer before (according to a memory allocation failure). This issue was detected by using the Coccinelle software. Thus return directly after a failed kasprintf() call. Fixes: 26409dd045892 ("of: unittest: Add pci_dt_testdrv pci driver") Signed-off-by: Markus Elfring --- drivers/of/unittest.c | 6 ++++++ 1 file changed, 6 insertions(+) -- 2.43.0 diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index e9e90e96600e..a46268fe8d2a 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -3990,6 +3990,9 @@ static int of_unittest_pci_node_verify(struct pci_dev *pdev, bool add) if (add) { path = kasprintf(GFP_KERNEL, "%pOF/pci-ep-bus@0/unittest-pci@100", pnp); + if (!path) + return -ENOMEM; + np = of_find_node_by_path(path); unittest(np, "Failed to get unittest-pci node under PCI node\n"); if (!np) { @@ -4003,6 +4006,9 @@ static int of_unittest_pci_node_verify(struct pci_dev *pdev, bool add) rc = -ENODEV; } else { path = kasprintf(GFP_KERNEL, "%pOF/pci-ep-bus@0", pnp); + if (!path) + return -ENOMEM; + np = of_find_node_by_path(path); unittest(!np, "Child device tree node is not removed\n"); child_dev = device_find_any_child(&pdev->dev);