Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1384091 > unrolled thread

[PATCH v3] i2c: designware-platdrv: fix unbalanced clk enable and prepare

Started byJisheng Zhang <jszhang@marvell.com>
First post2016-04-21 13:30 +0200
Last post2016-04-21 14:30 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v3] i2c: designware-platdrv: fix unbalanced clk enable and prepare Jisheng Zhang <jszhang@marvell.com> - 2016-04-21 13:30 +0200
    Re: [PATCH v3] i2c: designware-platdrv: fix unbalanced clk enable  and prepare Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-04-21 14:30 +0200

#1384091 — [PATCH v3] i2c: designware-platdrv: fix unbalanced clk enable and prepare

FromJisheng Zhang <jszhang@marvell.com>
Date2016-04-21 13:30 +0200
Subject[PATCH v3] i2c: designware-platdrv: fix unbalanced clk enable and prepare
Message-ID<rqkY2-8lx-3@gated-at.bofh.it>
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.

Signed-off-by: Jisheng Zhang <jszhang@marvell.com>
---
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(-)

diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index d656657..a771781 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -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;
 }
-- 
2.8.1

[toc] | [next] | [standalone]


#1384145 — Re: [PATCH v3] i2c: designware-platdrv: fix unbalanced clk enable and prepare

FromAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Date2016-04-21 14:30 +0200
SubjectRe: [PATCH v3] i2c: designware-platdrv: fix unbalanced clk enable and prepare
Message-ID<rqlU6-EL-7@gated-at.bofh.it>
In reply to#1384091
On Thu, 2016-04-21 at 19:22 +0800, Jisheng Zhang wrote:
> 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

> 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.

(() -> ()

> 
> Signed-off-by: Jisheng Zhang <jszhang@marvell.com>

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.

> ---
> 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(-)
> 
> diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c
> b/drivers/i2c/busses/i2c-designware-platdrv.c
> index d656657..a771781 100644
> --- a/drivers/i2c/busses/i2c-designware-platdrv.c
> +++ b/drivers/i2c/busses/i2c-designware-platdrv.c
> @@ -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;
>  }

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web