* [PATCH] i2c: cadence: fix clk disable/unprepare underflow warning on remove
@ 2026-09-18 16:45 Cong Nguyen
2026-10-19 16:42 ` Pandey, Radhey Shyam
0 siblings, 1 reply; 2+ messages in thread
From: Cong Nguyen @ 2026-09-18 16:45 UTC (permalink / raw)
To: Andi Shyti
Cc: Michal Simek, Manikanta Guntupalli, linux-arm-kernel, linux-i2c,
linux-kernel
cdns_i2c_probe() enables id->clk via devm_clk_get_enabled(), which
auto-disables/unprepares it on unbind. Runtime PM autosuspend
separately enables/disables the same clock as the device idles and
wakes. remove() never forces the device back active first -- if it's
runtime-suspended at removal (routine after any idle period, not a
rare race), the devm cleanup then disables an already-disabled clock,
hitting the "already disabled"/"already unprepared" WARN().
i2c-imx.c has the identical shape and already gets this right:
pm_runtime_get_sync() first, balanced with pm_runtime_put_noidle()
before the final disable. Apply the same fix here.
Fixes: 3d36dd1161ca ("i2c: cadence: Simplify using devm_clk_get_enabled()")
Assisted-by: LLM
Signed-off-by: Cong Nguyen <congnt264@gmail.com>
---
drivers/i2c/busses/i2c-cadence.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index da8770182a18..d0919593456b 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -1625,14 +1625,21 @@ static int cdns_i2c_probe(struct platform_device *pdev)
static void cdns_i2c_remove(struct platform_device *pdev)
{
struct cdns_i2c *id = platform_get_drvdata(pdev);
+ int ret;
+
+ ret = pm_runtime_get_sync(&pdev->dev);
+ if (ret < 0)
+ dev_err(&pdev->dev, "Failed to resume device (%pe)\n", ERR_PTR(ret));
- pm_runtime_disable(&pdev->dev);
- pm_runtime_set_suspended(&pdev->dev);
pm_runtime_dont_use_autosuspend(&pdev->dev);
i2c_del_adapter(&id->adap);
clk_notifier_unregister(id->clk, &id->clk_rate_change_nb);
reset_control_assert(id->reset);
+
+ pm_runtime_put_noidle(&pdev->dev);
+ pm_runtime_disable(&pdev->dev);
+ pm_runtime_set_suspended(&pdev->dev);
}
/**
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] i2c: cadence: fix clk disable/unprepare underflow warning on remove
2026-09-18 16:45 [PATCH] i2c: cadence: fix clk disable/unprepare underflow warning on remove Cong Nguyen
@ 2026-10-19 16:42 ` Pandey, Radhey Shyam
0 siblings, 0 replies; 2+ messages in thread
From: Pandey, Radhey Shyam @ 2026-10-19 16:42 UTC (permalink / raw)
To: Cong Nguyen, Andi Shyti
Cc: Michal Simek, Manikanta Guntupalli, linux-arm-kernel, linux-i2c,
linux-kernel
On 9/18/2026 10:15 PM, Cong Nguyen wrote:
> cdns_i2c_probe() enables id->clk via devm_clk_get_enabled(), which
> auto-disables/unprepares it on unbind. Runtime PM autosuspend
> separately enables/disables the same clock as the device idles and
> wakes. remove() never forces the device back active first -- if it's
> runtime-suspended at removal (routine after any idle period, not a
> rare race), the devm cleanup then disables an already-disabled clock,
> hitting the "already disabled"/"already unprepared" WARN().
>
> i2c-imx.c has the identical shape and already gets this right:
> pm_runtime_get_sync() first, balanced with pm_runtime_put_noidle()
> before the final disable. Apply the same fix here.
>
> Fixes: 3d36dd1161ca ("i2c: cadence: Simplify using devm_clk_get_enabled()")
> Assisted-by: LLM
> Signed-off-by: Cong Nguyen <congnt264@gmail.com>
> ---
> drivers/i2c/busses/i2c-cadence.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
> index da8770182a18..d0919593456b 100644
> --- a/drivers/i2c/busses/i2c-cadence.c
> +++ b/drivers/i2c/busses/i2c-cadence.c
> @@ -1625,14 +1625,21 @@ static int cdns_i2c_probe(struct platform_device *pdev)
> static void cdns_i2c_remove(struct platform_device *pdev)
> {
> struct cdns_i2c *id = platform_get_drvdata(pdev);
> + int ret;
> +
> + ret = pm_runtime_get_sync(&pdev->dev);
> + if (ret < 0)
> + dev_err(&pdev->dev, "Failed to resume device (%pe)\n", ERR_PTR(ret));
Nit - With this error handling introduced we also need to sync remove()
documentation.
* Return: 0 always
With that fixed.
Reviewed-by: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
Thanks!
>
> - pm_runtime_disable(&pdev->dev);
> - pm_runtime_set_suspended(&pdev->dev);
> pm_runtime_dont_use_autosuspend(&pdev->dev);
>
> i2c_del_adapter(&id->adap);
> clk_notifier_unregister(id->clk, &id->clk_rate_change_nb);
> reset_control_assert(id->reset);
> +
> + pm_runtime_put_noidle(&pdev->dev);
> + pm_runtime_disable(&pdev->dev);
> + pm_runtime_set_suspended(&pdev->dev);
> }
>
> /**
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-19 16:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-18 16:45 [PATCH] i2c: cadence: fix clk disable/unprepare underflow warning on remove Cong Nguyen
2026-10-19 16:42 ` Pandey, Radhey Shyam
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox