Skip to contentSkip to conversation

phy: rockchip-usb: fix reset control leak

PATCH Superseded Xia Yan 2 participants 3 messages Dec 1 – Dec 2

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Xia Yan

author
#0 lore raw

PATCH v2 1/1 phy: rockchip-usb: fix reset control leak

rockchip_usb_phy_init() acquires a reset control from each PHY child node but never releases it on probe failure or driver detach.

The leaked exclusive control prevents a later probe from acquiring the same reset. Since lookup errors are converted to NULL, subsequent PHY reset calls silently skip the hardware reset.

Move the lookup after devm_phy_create() and use devm_reset_control_get() with the PHY device. Its firmware node is the original PHY child node, so this keeps the lookup on the same node and releases the control when the PHY device is released. Keep the existing handling of lookup errors.

Found during review of reset-control lifetimes.

Build-tested the driver object directly on x86_64 with W=1 and reset support enabled. No ARM or hardware testing.

Fixes 0f74ab59ce87 ("phy: rockchip-usb: use rockchip_usb_phy_reset to reset phy during wakeup")

---

Notes (rockchip-v2-20261201):
Changes in v2:
- Drop the stable Cc as requested by Manivannan Sadhasivam.
- Use devm_reset_control_get() on the PHY device after devm_phy_create(), replacing the custom reset_control_put() action from v1.

v1: https://lore.kernel.org/linux-phy/[email protected]/
Review: https://patchwork.kernel.org/comment/27414254/

 drivers/phy/rockchip/phy-rockchip-usb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/phy/rockchip/phy-rockchip-usb.c +4 -4
index c5a2853a63d3..a3adb0a01b85 100644
@@ -218,10 +218,6 @@ static int rockchip_usb_phy_init(struct rockchip_usb_phy_base *base,
 		return -EINVAL;
 	}
 
-	rk_phy->reset = of_reset_control_get(child, "phy-reset");
-	if (IS_ERR(rk_phy->reset))
-		rk_phy->reset = NULL;
-
 	rk_phy->reg_offset = reg_offset;
 
 	rk_phy->clk = of_clk_get_by_name(child, "phyclk");
@@ -285,6 +281,10 @@ static int rockchip_usb_phy_init(struct rockchip_usb_phy_base *base,
 	}
 	phy_set_drvdata(rk_phy->phy, rk_phy);
 
+	rk_phy->reset = devm_reset_control_get(&rk_phy->phy->dev, "phy-reset");
+	if (IS_ERR(rk_phy->reset))
+		rk_phy->reset = NULL;
+
 	rk_phy->vbus = devm_regulator_get_optional(&rk_phy->phy->dev, "vbus");
 	if (IS_ERR(rk_phy->vbus)) {
 		if (PTR_ERR(rk_phy->vbus) == -EPROBE_DEFER)

base-commit: 9a0dd2a09484e5ba45eb8e6ab58c0effe18703a3

Signature · 1 line
2.43.0
#1 lore raw

Hi,

Quoted 13 lines · Xia Yan

rockchip_usb_phy_init() acquires a reset control from each PHY child node but never releases it on probe failure or driver detach.

The leaked exclusive control prevents a later probe from acquiring the same reset. Since lookup errors are converted to NULL, subsequent PHY reset calls silently skip the hardware reset.

Move the lookup after devm_phy_create() and use devm_reset_control_get() with the PHY device. Its firmware node is the original PHY child node, so this keeps the lookup on the same node and releases the control when the PHY device is released. Keep the existing handling of lookup errors.

Quoted 7 lines

Found during review of reset-control lifetimes.

Build-tested the driver object directly on x86_64 with W=1 and reset support enabled. No ARM or hardware testing.

Fixes 0f74ab59ce87 ("phy: rockchip-usb: use rockchip_usb_phy_reset to reset phy during wakeup")

devm_reset_control_get() is deprecated in favor of devm_reset_control_get_exclusive(), so it makes sense to directly use the second one.

Greetings,

-- Sebastian

Quoted 49 lines

---

Notes (rockchip-v2-20261201):
Changes in v2:
- Drop the stable Cc as requested by Manivannan Sadhasivam.
- Use devm_reset_control_get() on the PHY device after devm_phy_create(), replacing the custom reset_control_put() action from v1.

v1: https://lore.kernel.org/linux-phy/[email protected]/
Review: https://patchwork.kernel.org/comment/27414254/

 drivers/phy/rockchip/phy-rockchip-usb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/phy/rockchip/phy-rockchip-usb.c +4 -4
index c5a2853a63d3..a3adb0a01b85 100644
@@ -218,10 +218,6 @@ static int rockchip_usb_phy_init(struct rockchip_usb_phy_base *base,
 		return -EINVAL;
 	}
 
-	rk_phy->reset = of_reset_control_get(child, "phy-reset");
-	if (IS_ERR(rk_phy->reset))
-		rk_phy->reset = NULL;
-
 	rk_phy->reg_offset = reg_offset;
 
 	rk_phy->clk = of_clk_get_by_name(child, "phyclk");
@@ -285,6 +281,10 @@ static int rockchip_usb_phy_init(struct rockchip_usb_phy_base *base,
 	}
 	phy_set_drvdata(rk_phy->phy, rk_phy);
 
+	rk_phy->reset = devm_reset_control_get(&rk_phy->phy->dev, "phy-reset");
+	if (IS_ERR(rk_phy->reset))
+		rk_phy->reset = NULL;
+
 	rk_phy->vbus = devm_regulator_get_optional(&rk_phy->phy->dev, "vbus");
 	if (IS_ERR(rk_phy->vbus)) {
 		if (PTR_ERR(rk_phy->vbus) == -EPROBE_DEFER)

base-commit: 9a0dd2a09484e5ba45eb8e6ab58c0effe18703a3

Signature · 1 line
2.43.0
Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
author
#2 lore raw

Hi Sebastian,

Thanks for pointing this out. I have changed the call to devm_reset_control_get_exclusive() in v3:
https://patchwork.kernel.org/project/linux-phy/patch/[email protected]/

The deprecated wrapper already calls the exclusive helper, so this keeps the same exclusive semantics and device-managed lifetime. The driver object was rebuilt on x86_64 with W=1 and reset support enabled. No ARM or hardware testing.

Thanks,
Xia Yan