]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
usb: dwc3: st: use scoped device node handling to simplify error paths
authorKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Wed, 14 Aug 2024 10:35:37 +0000 (12:35 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 3 Sep 2024 07:52:45 +0000 (09:52 +0200)
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: Patrice Chotard <patrice.chotard@foss.st.com>
Link: https://lore.kernel.org/r/20240814-b4-cleanup-h-of-node-put-usb-v1-1-95481b9682bc@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/dwc3/dwc3-st.c

index c8c7cd0c179693d1882e2bea56e6df8b647c9c0f..98f43d7082d7b0fcc309acf262251fa728b2a828 100644 (file)
@@ -14,6 +14,7 @@
  * Inspired by dwc3-omap.c and dwc3-exynos.c.
  */
 
+#include <linux/cleanup.h>
 #include <linux/delay.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
@@ -197,7 +198,7 @@ static int st_dwc3_probe(struct platform_device *pdev)
        struct st_dwc3 *dwc3_data;
        struct resource *res;
        struct device *dev = &pdev->dev;
-       struct device_node *node = dev->of_node, *child;
+       struct device_node *node = dev->of_node;
        struct platform_device *child_pdev;
        struct regmap *regmap;
        int ret;
@@ -227,6 +228,13 @@ static int st_dwc3_probe(struct platform_device *pdev)
        dev_vdbg(&pdev->dev, "glue-logic addr 0x%pK, syscfg-reg offset 0x%x\n",
                 dwc3_data->glue_base, dwc3_data->syscfg_reg_off);
 
+       struct device_node *child __free(device_node) = of_get_compatible_child(node,
+                                                                               "snps,dwc3");
+       if (!child) {
+               dev_err(&pdev->dev, "failed to find dwc3 core node\n");
+               return -ENODEV;
+       }
+
        dwc3_data->rstc_pwrdn =
                devm_reset_control_get_exclusive(dev, "powerdown");
        if (IS_ERR(dwc3_data->rstc_pwrdn)) {
@@ -248,18 +256,11 @@ static int st_dwc3_probe(struct platform_device *pdev)
        /* Manage SoftReset */
        reset_control_deassert(dwc3_data->rstc_rst);
 
-       child = of_get_compatible_child(node, "snps,dwc3");
-       if (!child) {
-               dev_err(&pdev->dev, "failed to find dwc3 core node\n");
-               ret = -ENODEV;
-               goto err_node_put;
-       }
-
        /* Allocate and initialize the core */
        ret = of_platform_populate(node, NULL, NULL, dev);
        if (ret) {
                dev_err(dev, "failed to add dwc3 core\n");
-               goto err_node_put;
+               goto undo_softreset;
        }
 
        child_pdev = of_find_device_by_node(child);
@@ -270,7 +271,6 @@ static int st_dwc3_probe(struct platform_device *pdev)
        }
 
        dwc3_data->dr_mode = usb_get_dr_mode(&child_pdev->dev);
-       of_node_put(child);
        platform_device_put(child_pdev);
 
        /*
@@ -282,8 +282,7 @@ static int st_dwc3_probe(struct platform_device *pdev)
        ret = st_dwc3_drd_init(dwc3_data);
        if (ret) {
                dev_err(dev, "drd initialisation failed\n");
-               of_platform_depopulate(dev);
-               goto undo_softreset;
+               goto depopulate;
        }
 
        /* ST glue logic init */
@@ -294,8 +293,6 @@ static int st_dwc3_probe(struct platform_device *pdev)
 
 depopulate:
        of_platform_depopulate(dev);
-err_node_put:
-       of_node_put(child);
 undo_softreset:
        reset_control_assert(dwc3_data->rstc_rst);
 undo_powerdown: