* [PATCH] of: unittest: Return directly after a failed kasprintf() call in of_unittest_pci_node_verify()
@ 2024-01-23 17:38 Markus Elfring
0 siblings, 0 replies; only message in thread
From: Markus Elfring @ 2024-01-23 17:38 UTC (permalink / raw)
To: devicetree, kernel-janitors, Frank Rowand, Lizhi Hou, Rob Herring
Cc: LKML, Kunwu Chan
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2024-01-23 17:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-23 17:38 [PATCH] of: unittest: Return directly after a failed kasprintf() call in of_unittest_pci_node_verify() Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).