Skip to contentSkip to conversation

i2c: designware-platdrv: fix unbalanced clk enable and prepare

PATCH Superseded Jisheng Zhang 2 participants 2 messages Apr 21, 2016

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 i2c: designware-platdrv: fix unbalanced clk enable and prepare

If i2c_dw_probe() fails, we should disable and unprepare the clock, otherwise the clock enable and prepare is left unbalanced.

In dw_i2c_plat_remove(), we'd better to not rely on rpm to disable and unprepare the clock since CONFIG_PM may be disabled when configuring the kernel. So we explicitly disable and unprepare the clock in dw_i2c_plat_remove() rather than implicitly rely on pm_runtime_put_sync(). To keep the device usage count balanced, we call pm_runtime_put_noidle(() to decrease the usage count.

---
Since v2:
- s/clk/clock
- describe why use pm_runtime_put_noidle()

Since v1:
- fix commit msg: "not rely on rpm" rather than "rely on rpm"
- call i2c_dw_plat_prepare_clk after pm_rumtime_disable()

 drivers/i2c/busses/i2c-designware-platdrv.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-designware-platdrv.c +10 -6
index d656657..a771781 100644
@@ -253,8 +253,11 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
 	}
 
 	r = i2c_dw_probe(dev);
-	if (r && !dev->pm_runtime_disabled)
-		pm_runtime_disable(&pdev->dev);
+	if (r) {
+		if (!dev->pm_runtime_disabled)
+			pm_runtime_disable(&pdev->dev);
+		i2c_dw_plat_prepare_clk(dev, false);
+	}
 
 	return r;
 }
@@ -264,15 +267,16 @@ static int dw_i2c_plat_remove(struct platform_device *pdev)
 	struct dw_i2c_dev *dev = platform_get_drvdata(pdev);
 
 	pm_runtime_get_sync(&pdev->dev);
+	pm_runtime_dont_use_autosuspend(&pdev->dev);
+	if (!dev->pm_runtime_disabled)
+		pm_runtime_disable(&pdev->dev);
+	pm_runtime_put_noidle(&pdev->dev);
 
 	i2c_del_adapter(&dev->adapter);
 
 	i2c_dw_disable(dev);
 
-	pm_runtime_dont_use_autosuspend(&pdev->dev);
-	pm_runtime_put_sync(&pdev->dev);
-	if (!dev->pm_runtime_disabled)
-		pm_runtime_disable(&pdev->dev);
+	i2c_dw_plat_prepare_clk(dev, false);
 
 	return 0;
 }
Signature · 1 line
2.8.1
#1 lore raw
Quoted 4 lines · Jisheng Zhang

If i2c_dw_probe() fails, we should disable and unprepare the clock, otherwise the clock enable and prepare is left unbalanced.

In dw_i2c_plat_remove(), we'd better to not rely on rpm to disable

Sorry, didn't notice earlier
rpm -> runtime PM

Quoted 5 lines

and unprepare the clock since CONFIG_PM may be disabled when configuring the kernel. So we explicitly disable and unprepare the clock in dw_i2c_plat_remove() rather than implicitly rely on pm_runtime_put_sync(). To keep the device usage count balanced, we call pm_runtime_put_noidle(() to decrease the usage count.

(() -> ()

Quoted 2 lines

I don't know if Wolfram wants you to send new version, and I dunno if others still have comments, but

Patch is in a good shape, but I think we have to carefully check the runtime PM change.

Quoted 54 lines

---
Since v2:
 - s/clk/clock
 - describe why use pm_runtime_put_noidle()

Since v1:
 - fix commit msg: "not rely on rpm" rather than "rely on rpm"
 - call i2c_dw_plat_prepare_clk after pm_rumtime_disable()

 drivers/i2c/busses/i2c-designware-platdrv.c | 16 ++++++++++------

 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-designware-platdrv.c +0 -0
index d656657..a771781 100644
@@ -253,8 +253,11 @@ static int dw_i2c_plat_probe(struct
 platform_device *pdev)
  	}


  r = i2c_dw_probe(dev);

drivers/i2c/busses/i2c-designware-platdrv.c +5 -2
-	if (r && !dev->pm_runtime_disabled)
-		pm_runtime_disable(&pdev->dev);
+	if (r) {
+		if (!dev->pm_runtime_disabled)
+			pm_runtime_disable(&pdev->dev);
+		i2c_dw_plat_prepare_clk(dev, false);
+	}


  return r;
 }

drivers/i2c/busses/i2c-designware-platdrv.c +0 -0
@@ -264,15 +267,16 @@ static int dw_i2c_plat_remove(struct
 platform_device *pdev)
  	struct dw_i2c_dev *dev = platform_get_drvdata(pdev);


  pm_runtime_get_sync(&pdev->dev);

drivers/i2c/busses/i2c-designware-platdrv.c +4 -0
+	pm_runtime_dont_use_autosuspend(&pdev->dev);
+	if (!dev->pm_runtime_disabled)
+		pm_runtime_disable(&pdev->dev);
+	pm_runtime_put_noidle(&pdev->dev);


  i2c_del_adapter(&dev->adapter);

  i2c_dw_disable(dev);

drivers/i2c/busses/i2c-designware-platdrv.c +1 -4
-	pm_runtime_dont_use_autosuspend(&pdev->dev);
-	pm_runtime_put_sync(&pdev->dev);
-	if (!dev->pm_runtime_disabled)
-		pm_runtime_disable(&pdev->dev);
+	i2c_dw_plat_prepare_clk(dev, false);


  return 0;
 }

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy