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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
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@xxxxxxxxxxxxxxxxxxxxx>
---
 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






[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux