Skip to contentSkip to conversation

i2c: cadence: fix clk disable/unprepare underflow warning on remove

PATCH In review Cong Nguyen 2 participants 2 messages Sep 18 – Oct 19

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: cadence: fix clk disable/unprepare underflow warning on remove

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
---
 drivers/i2c/busses/i2c-cadence.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-cadence.c +9 -2
index da8770182a18..d0919593456b 100644
@@ -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);
 }
 
 /**
Signature · 1 line
2.25.1
Reviewed-by Radhey Shyam Pandey on v1 1/1
#1 lore raw
Quoted 24 lines · Cong Nguyen

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
---
  drivers/i2c/busses/i2c-cadence.c | 11 +++++++++--
  1 file changed, 9 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-cadence.c +0 -0
index da8770182a18..d0919593456b 100644

drivers/i2c/busses/i2c-cadence.c static int cdns_i2c_probe(struct platform_device *pdev) · line 1632

Quoted 8 lines
drivers/i2c/busses/i2c-cadence.c +5 -0
@@ -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.

Thanks!

Quoted 15 lines
drivers/i2c/busses/i2c-cadence.c +4 -2
-	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);
  }
 
  /**