]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
phy: renesas: rcar-gen3-usb2: Use devm_pm_runtime_enable()
authorTommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Mon, 22 Dec 2025 13:43:45 +0000 (14:43 +0100)
committerVinod Koul <vkoul@kernel.org>
Wed, 21 Jan 2026 08:46:02 +0000 (14:16 +0530)
Replace pm_runtime_enable() with devm_pm_runtime_enable() to ensure proper
cleanup if the probe fails. This change enhances driver reliability by
avoiding resource leaks, as the devm-managed version automatically handles
disabling at probe failure or device removal.

Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Link: https://patch.msgid.link/ca028d41f84227efeccb0cbdff22fbf16e5cf6ab.1766405010.git.tommaso.merciai.xr@bp.renesas.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/phy/renesas/phy-rcar-gen3-usb2.c

index 4c7a46f1f16b87085e722fd8cf42c555e99e48d5..94a4521d71874be5dc0bcb9a9864fd02b379c74d 100644 (file)
@@ -862,30 +862,29 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
         * devm_phy_create() will call pm_runtime_enable(&phy->dev);
         * And then, phy-core will manage runtime pm for this device.
         */
-       pm_runtime_enable(dev);
+       ret = devm_pm_runtime_enable(dev);
+       if (ret)
+               return dev_err_probe(dev, ret, "Failed to enable pm_runtime\n");
 
        channel->phy_data = of_device_get_match_data(dev);
-       if (!channel->phy_data) {
-               ret = -EINVAL;
-               goto error;
-       }
+       if (!channel->phy_data)
+               return -EINVAL;
 
        platform_set_drvdata(pdev, channel);
        channel->dev = dev;
 
        ret = rcar_gen3_phy_usb2_init_bus(channel);
        if (ret)
-               goto error;
+               return ret;
 
        spin_lock_init(&channel->lock);
        for (i = 0; i < NUM_OF_PHYS; i++) {
                channel->rphys[i].phy = devm_phy_create(dev, NULL,
                                                        channel->phy_data->phy_usb2_ops);
-               if (IS_ERR(channel->rphys[i].phy)) {
-                       dev_err(dev, "Failed to create USB2 PHY\n");
-                       ret = PTR_ERR(channel->rphys[i].phy);
-                       goto error;
-               }
+               if (IS_ERR(channel->rphys[i].phy))
+                       return dev_err_probe(dev, PTR_ERR(channel->rphys[i].phy),
+                                            "Failed to create USB2 PHY\n");
+
                channel->rphys[i].ch = channel;
                channel->rphys[i].int_enable_bits = rcar_gen3_int_enable[i];
                phy_set_drvdata(channel->rphys[i].phy, &channel->rphys[i]);
@@ -896,44 +895,36 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
        else
                channel->vbus = devm_regulator_get_optional(dev, "vbus");
        if (IS_ERR(channel->vbus)) {
-               if (PTR_ERR(channel->vbus) == -EPROBE_DEFER) {
-                       ret = PTR_ERR(channel->vbus);
-                       goto error;
-               }
+               if (PTR_ERR(channel->vbus) == -EPROBE_DEFER)
+                       return PTR_ERR(channel->vbus);
+
                channel->vbus = NULL;
        }
 
        irq = platform_get_irq_optional(pdev, 0);
        if (irq < 0 && irq != -ENXIO) {
-               ret = irq;
-               goto error;
+               return irq;
        } else if (irq > 0) {
                INIT_WORK(&channel->work, rcar_gen3_phy_usb2_work);
                ret = devm_request_irq(dev, irq, rcar_gen3_phy_usb2_irq,
                                       IRQF_SHARED, dev_name(dev), channel);
-               if (ret < 0) {
-                       dev_err(dev, "Failed to request irq (%d)\n", irq);
-                       goto error;
-               }
+               if (ret < 0)
+                       return dev_err_probe(dev, ret,
+                                            "Failed to request irq (%d)\n",
+                                            irq);
        }
 
        provider = devm_of_phy_provider_register(dev, rcar_gen3_phy_usb2_xlate);
        if (IS_ERR(provider)) {
-               dev_err(dev, "Failed to register PHY provider\n");
-               ret = PTR_ERR(provider);
-               goto error;
+               return dev_err_probe(dev, PTR_ERR(provider),
+                                    "Failed to register PHY provider\n");
        } else if (channel->is_otg_channel) {
                ret = device_create_file(dev, &dev_attr_role);
                if (ret < 0)
-                       goto error;
+                       return ret;
        }
 
        return 0;
-
-error:
-       pm_runtime_disable(dev);
-
-       return ret;
 }
 
 static void rcar_gen3_phy_usb2_remove(struct platform_device *pdev)
@@ -942,8 +933,6 @@ static void rcar_gen3_phy_usb2_remove(struct platform_device *pdev)
 
        if (channel->is_otg_channel)
                device_remove_file(&pdev->dev, &dev_attr_role);
-
-       pm_runtime_disable(&pdev->dev);
 }
 
 static int rcar_gen3_phy_usb2_suspend(struct device *dev)