From: Markus Elfring <Markus.Elfring@web.de>
To: devicetree@vger.kernel.org, kernel-janitors@vger.kernel.org,
Frank Rowand <frowand.list@gmail.com>,
Lizhi Hou <lizhi.hou@amd.com>, Rob Herring <robh+dt@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>, Kunwu Chan <chentao@kylinos.cn>
Subject: [PATCH] of: unittest: Return directly after a failed kasprintf() call in of_unittest_pci_node_verify()
Date: Tue, 23 Jan 2024 18:38:42 +0100 [thread overview]
Message-ID: <0b2bccfb-d1a3-4c2e-b1d3-159630edf21a@web.de> (raw)
From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
drivers/of/unittest.c | 6 ++++++
1 file changed, 6 insertions(+)
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);
--
2.43.0
reply other threads:[~2024-01-23 17:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0b2bccfb-d1a3-4c2e-b1d3-159630edf21a@web.de \
--to=markus.elfring@web.de \
--cc=chentao@kylinos.cn \
--cc=devicetree@vger.kernel.org \
--cc=frowand.list@gmail.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizhi.hou@amd.com \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®