[PATCH v4 02/22] phy: renesas: rcar-gen3-usb2: Use devm_pm_runtime_enable()

Tommaso Merciai
2025-11-21T15:13:04Z

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>
---
v3->v4:
- No changes

v2->v3:
- No changes

v1->v2:
- No changes

drivers/phy/renesas/phy-rcar-gen3-usb2.c | 53 ++++++++++--------------
1 file changed, 21 insertions(+), 32 deletions(-)

diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
index 582de10d5beb..41e0c818ae34 100644
--- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c
@@ -852,30 +852,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]);
@@ -886,44 +885,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)
@@ -932,8 +923,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)
--
2.43.0