Re: [bug report] irqchip/mbigen: move to use bus_get_dev_root()

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

 





On 2023/5/4 15:34, Dan Carpenter wrote:
Hello Greg Kroah-Hartman,

The patch fea087fc291b: "irqchip/mbigen: move to use
bus_get_dev_root()" from Mar 13, 2023, leads to the following Smatch
static checker warning:

	drivers/irqchip/irq-mbigen.c:258 mbigen_of_create_domain()
	error: potentially dereferencing uninitialized 'child'.

drivers/irqchip/irq-mbigen.c
     235 static int mbigen_of_create_domain(struct platform_device *pdev,
     236                                    struct mbigen_device *mgn_chip)
     237 {
     238         struct device *parent;
     239         struct platform_device *child;
     240         struct irq_domain *domain;
     241         struct device_node *np;
     242         u32 num_pins;
     243
     244         for_each_child_of_node(pdev->dev.of_node, np) {
     245                 if (!of_property_read_bool(np, "interrupt-controller"))
     246                         continue;
     247
     248                 parent = bus_get_dev_root(&platform_bus_type);
     249                 if (parent) {

Smatch is concerned that "parent" can be NULL.  Probably unlikely in
real life.

How about move bus_get_dev_root() out of the loop.

diff --git a/drivers/irqchip/irq-mbigen.c b/drivers/irqchip/irq-mbigen.c
index eada5e0e3eb9..954a55ed1f2b 100644
--- a/drivers/irqchip/irq-mbigen.c
+++ b/drivers/irqchip/irq-mbigen.c
@@ -240,26 +240,25 @@ static int mbigen_of_create_domain(struct platform_device *pdev,
 	struct irq_domain *domain;
 	struct device_node *np;
 	u32 num_pins;
+	int ret = -ENODEV;
+
+	parent = bus_get_dev_root(&platform_bus_type);
+	if (!parent)
+		return ret;

 	for_each_child_of_node(pdev->dev.of_node, np) {
 		if (!of_property_read_bool(np, "interrupt-controller"))
 			continue;

-		parent = bus_get_dev_root(&platform_bus_type);
-		if (parent) {
-			child = of_platform_device_create(np, NULL, parent);
-			put_device(parent);
-			if (!child) {
-				of_node_put(np);
-				return -ENOMEM;
-			}
-		}
+		child = of_platform_device_create(np, NULL, parent);
+		if (!child)
+			goto out_put;

 		if (of_property_read_u32(child->dev.of_node, "num-pins",
 					 &num_pins) < 0) {
 			dev_err(&pdev->dev, "No num-pins property\n");
-			of_node_put(np);
-			return -EINVAL;
+			ret = -EINVAL;
+			goto out_put;
 		}

 		domain = platform_msi_create_device_domain(&child->dev, num_pins,
@@ -267,12 +266,17 @@ static int mbigen_of_create_domain(struct platform_device *pdev,
 							   &mbigen_domain_ops,
 							   mgn_chip);
 		if (!domain) {
-			of_node_put(np);
-			return -ENOMEM;
+			ret = -ENOMEM;
+			goto out_put;
 		}
 	}

 	return 0;
+
+out_put:
+	of_node_put(np);
+	put_device(parent);
+	return ret;
 }





regards,
dan carpenter



[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux