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

Dan Carpenter reported that commit fea087fc291b "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

authored by Kefeng Wang and committed by Marc Zyngier cddb536a 14130211

Changed files
+18 -13
drivers
irqchip
+18 -13
drivers/irqchip/irq-mbigen.c
··· 240 240 struct irq_domain *domain; 241 241 struct device_node *np; 242 242 u32 num_pins; 243 + int ret = 0; 244 + 245 + parent = bus_get_dev_root(&platform_bus_type); 246 + if (!parent) 247 + return -ENODEV; 243 248 244 249 for_each_child_of_node(pdev->dev.of_node, np) { 245 250 if (!of_property_read_bool(np, "interrupt-controller")) 246 251 continue; 247 252 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; 256 257 } 257 258 258 259 if (of_property_read_u32(child->dev.of_node, "num-pins", 259 260 &num_pins) < 0) { 260 261 dev_err(&pdev->dev, "No num-pins property\n"); 261 - of_node_put(np); 262 - return -EINVAL; 262 + ret = -EINVAL; 263 + break; 263 264 } 264 265 265 266 domain = platform_msi_create_device_domain(&child->dev, num_pins, ··· 268 267 &mbigen_domain_ops, 269 268 mgn_chip); 270 269 if (!domain) { 271 - of_node_put(np); 272 - return -ENOMEM; 270 + ret = -ENOMEM; 271 + break; 273 272 } 274 273 } 275 274 276 - return 0; 275 + put_device(parent); 276 + if (ret) 277 + of_node_put(np); 278 + 279 + return ret; 277 280 } 278 281 279 282 #ifdef CONFIG_ACPI