Skip to content

Commit cddb536

Browse files
Kefeng WangMarc Zyngier
authored andcommitted
irqchip/mbigen: Unify the error handling in mbigen_of_create_domain()
Dan Carpenter reported that commit fea087f "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: Dan Carpenter <dan.carpenter@linaro.org> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20230505090654.12793-1-wangkefeng.wang@huawei.com
1 parent 1413021 commit cddb536

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

drivers/irqchip/irq-mbigen.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -240,39 +240,44 @@ static int mbigen_of_create_domain(struct platform_device *pdev,
240240
struct irq_domain *domain;
241241
struct device_node *np;
242242
u32 num_pins;
243+
int ret = 0;
244+
245+
parent = bus_get_dev_root(&platform_bus_type);
246+
if (!parent)
247+
return -ENODEV;
243248

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

248-
parent = bus_get_dev_root(&platform_bus_type);
249-
if (parent) {
250-
child = of_platform_device_create(np, NULL, parent);
251-
put_device(parent);
252-
if (!child) {
253-
of_node_put(np);
254-
return -ENOMEM;
255-
}
253+
child = of_platform_device_create(np, NULL, parent);
254+
if (!child) {
255+
ret = -ENOMEM;
256+
break;
256257
}
257258

258259
if (of_property_read_u32(child->dev.of_node, "num-pins",
259260
&num_pins) < 0) {
260261
dev_err(&pdev->dev, "No num-pins property\n");
261-
of_node_put(np);
262-
return -EINVAL;
262+
ret = -EINVAL;
263+
break;
263264
}
264265

265266
domain = platform_msi_create_device_domain(&child->dev, num_pins,
266267
mbigen_write_msg,
267268
&mbigen_domain_ops,
268269
mgn_chip);
269270
if (!domain) {
270-
of_node_put(np);
271-
return -ENOMEM;
271+
ret = -ENOMEM;
272+
break;
272273
}
273274
}
274275

275-
return 0;
276+
put_device(parent);
277+
if (ret)
278+
of_node_put(np);
279+
280+
return ret;
276281
}
277282

278283
#ifdef CONFIG_ACPI

0 commit comments

Comments
 (0)