From 49c9b71b45081e5e5eeb507a2d6edb80d332dc59 Mon Sep 17 00:00:00 2001 From: Biju Das Date: Thu, 6 Aug 2026 11:22:27 +0100 Subject: [PATCH] phy: renesas: phy-rcar-gen3-usb2: Fix devm action registration for disabled VBUS regulator devm_regulator_get_exclusive() initialises the regulator with enable_count = 1, requiring the consumer to disable it before release. The devm disable action was previously only registered when the caller explicitly requested enable, so when the regulator was left in its initial enabled state without an explicit enable call, the cleanup path skipped decrementing enable_count, triggering a WARN_ON during regulator release on device removal. Fix this by always registering the devm disable action based on the actual enabled state via regulator_is_enabled(), regardless of whether the caller requested an explicit enable. This covers both the explicitly enabled case and the initial state set by devm_regulator_get_exclusive(). Fixes: 24843404efe4 ("phy: renesas: phy-rcar-gen3-usb2: Control VBUS for RZ/G2L SoCs") Signed-off-by: Biju Das Link: https://patch.msgid.link/20260806102236.149159-9-biju.das.jz@bp.renesas.com Signed-off-by: Vinod Koul --- drivers/phy/renesas/phy-rcar-gen3-usb2.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c index d06fb52ed5f1..ef38c3b365d4 100644 --- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c +++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c @@ -905,15 +905,17 @@ static int rcar_gen3_phy_usb2_vbus_regulator_get_exclusive_enable(struct rcar_ge if (IS_ERR(channel->vbus)) return PTR_ERR(channel->vbus); - if (!enable) - return 0; + if (enable) { + ret = regulator_enable(channel->vbus); + if (ret) + return ret; + } - ret = regulator_enable(channel->vbus); - if (ret) - return ret; + if (regulator_is_enabled(channel->vbus)) + return devm_add_action_or_reset(dev, rcar_gen3_phy_usb2_vbus_disable_action, + channel->vbus); - return devm_add_action_or_reset(dev, rcar_gen3_phy_usb2_vbus_disable_action, - channel->vbus); + return 0; } static int rcar_gen3_phy_usb2_vbus_regulator_register(struct rcar_gen3_chan *channel)