Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: dwc3: imx8mp: use scoped device node handling to simplify error paths

Obtain the device node reference with scoped/cleanup.h to reduce error
handling and make the code a bit simpler. Scoped/cleanup.h coding style
expects variable declaration with initialization, so the
of_get_compatible_child() call has to be moved earlier, before any goto
jumps happen.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Link: https://lore.kernel.org/r/20240814-b4-cleanup-h-of-node-put-usb-v1-6-95481b9682bc@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Krzysztof Kozlowski and committed by
Greg Kroah-Hartman
34e8df2f 81d905b1

+8 -12
+8 -12
drivers/usb/dwc3/dwc3-imx8mp.c
··· 5 5 * Copyright (c) 2020 NXP. 6 6 */ 7 7 8 + #include <linux/cleanup.h> 8 9 #include <linux/clk.h> 9 10 #include <linux/interrupt.h> 10 11 #include <linux/io.h> ··· 148 147 static int dwc3_imx8mp_probe(struct platform_device *pdev) 149 148 { 150 149 struct device *dev = &pdev->dev; 151 - struct device_node *dwc3_np, *node = dev->of_node; 150 + struct device_node *node = dev->of_node; 152 151 struct dwc3_imx8mp *dwc3_imx; 153 152 struct resource *res; 154 153 int err, irq; ··· 194 193 return irq; 195 194 dwc3_imx->irq = irq; 196 195 196 + struct device_node *dwc3_np __free(device_node) = of_get_compatible_child(node, 197 + "snps,dwc3"); 198 + if (!dwc3_np) 199 + return dev_err_probe(dev, -ENODEV, "failed to find dwc3 core child\n"); 200 + 197 201 imx8mp_configure_glue(dwc3_imx); 198 202 199 203 pm_runtime_set_active(dev); ··· 207 201 if (err < 0) 208 202 goto disable_rpm; 209 203 210 - dwc3_np = of_get_compatible_child(node, "snps,dwc3"); 211 - if (!dwc3_np) { 212 - err = -ENODEV; 213 - dev_err(dev, "failed to find dwc3 core child\n"); 214 - goto disable_rpm; 215 - } 216 - 217 204 err = of_platform_populate(node, NULL, NULL, dev); 218 205 if (err) { 219 206 dev_err(&pdev->dev, "failed to create dwc3 core\n"); 220 - goto err_node_put; 207 + goto disable_rpm; 221 208 } 222 209 223 210 dwc3_imx->dwc3 = of_find_device_by_node(dwc3_np); ··· 219 220 err = -ENODEV; 220 221 goto depopulate; 221 222 } 222 - of_node_put(dwc3_np); 223 223 224 224 err = devm_request_threaded_irq(dev, irq, NULL, dwc3_imx8mp_interrupt, 225 225 IRQF_ONESHOT, dev_name(dev), dwc3_imx); ··· 234 236 235 237 depopulate: 236 238 of_platform_depopulate(dev); 237 - err_node_put: 238 - of_node_put(dwc3_np); 239 239 disable_rpm: 240 240 pm_runtime_disable(dev); 241 241 pm_runtime_put_noidle(dev);