Commit cddb536a authored by Kefeng Wang's avatar Kefeng Wang Committed by Marc Zyngier

irqchip/mbigen: Unify the error handling in mbigen_of_create_domain()

Dan Carpenter reported that commit fea087fc "irqchip/mbigen: move
to use bus_get_dev_root()" leads to the following Smatch static checker
warning:

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

It should not cause a problem on real hardware, but better to fix the
warning, let's move the bus_get_dev_root() out of the loop, and unify
the error handling to silence it.
Reported-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20230505090654.12793-1-wangkefeng.wang@huawei.com
parent 14130211
...@@ -240,26 +240,27 @@ static int mbigen_of_create_domain(struct platform_device *pdev, ...@@ -240,26 +240,27 @@ static int mbigen_of_create_domain(struct platform_device *pdev,
struct irq_domain *domain; struct irq_domain *domain;
struct device_node *np; struct device_node *np;
u32 num_pins; u32 num_pins;
int ret = 0;
parent = bus_get_dev_root(&platform_bus_type);
if (!parent)
return -ENODEV;
for_each_child_of_node(pdev->dev.of_node, np) { for_each_child_of_node(pdev->dev.of_node, np) {
if (!of_property_read_bool(np, "interrupt-controller")) if (!of_property_read_bool(np, "interrupt-controller"))
continue; continue;
parent = bus_get_dev_root(&platform_bus_type); child = of_platform_device_create(np, NULL, parent);
if (parent) { if (!child) {
child = of_platform_device_create(np, NULL, parent); ret = -ENOMEM;
put_device(parent); break;
if (!child) {
of_node_put(np);
return -ENOMEM;
}
} }
if (of_property_read_u32(child->dev.of_node, "num-pins", if (of_property_read_u32(child->dev.of_node, "num-pins",
&num_pins) < 0) { &num_pins) < 0) {
dev_err(&pdev->dev, "No num-pins property\n"); dev_err(&pdev->dev, "No num-pins property\n");
of_node_put(np); ret = -EINVAL;
return -EINVAL; break;
} }
domain = platform_msi_create_device_domain(&child->dev, num_pins, domain = platform_msi_create_device_domain(&child->dev, num_pins,
...@@ -267,12 +268,16 @@ static int mbigen_of_create_domain(struct platform_device *pdev, ...@@ -267,12 +268,16 @@ static int mbigen_of_create_domain(struct platform_device *pdev,
&mbigen_domain_ops, &mbigen_domain_ops,
mgn_chip); mgn_chip);
if (!domain) { if (!domain) {
of_node_put(np); ret = -ENOMEM;
return -ENOMEM; break;
} }
} }
return 0; put_device(parent);
if (ret)
of_node_put(np);
return ret;
} }
#ifdef CONFIG_ACPI #ifdef CONFIG_ACPI
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment