diff mbox series

of: unittest: Return directly after a failed kasprintf() call in of_unittest_pci_node_verify()

Message ID 0b2bccfb-d1a3-4c2e-b1d3-159630edf21a@web.de
State New
Headers show
Series of: unittest: Return directly after a failed kasprintf() call in of_unittest_pci_node_verify() | expand

Commit Message

Markus Elfring Jan. 23, 2024, 5:38 p.m. UTC
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(+)

--
2.43.0
diff mbox series

Patch

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);