diff mbox

[v3,07/10] clk: rollback set_rate_range changes on failure

Message ID 20170612194438.12298-8-jbrunet@baylibre.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Jerome Brunet June 12, 2017, 7:44 p.m. UTC
Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
---
 drivers/clk/clk.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Stephen Boyd July 12, 2017, 2:02 a.m. UTC | #1
On 06/12, Jerome Brunet wrote:
> Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>

There should be some commit text here describing the problem.
Also a Fixes: tag and please put this earlier in the series.

> ---
>  drivers/clk/clk.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index d91236e70a04..253f1d3f0971 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -1864,6 +1864,7 @@ EXPORT_SYMBOL_GPL(clk_set_rate_protect);
>  int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max)
>  {
>  	int ret = 0;
> +	unsigned int old_min, old_max;
>  
>  	if (!clk)
>  		return 0;
> @@ -1881,9 +1882,16 @@ int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max)
>  		clk_core_rate_unprotect(clk->core);
>  
>  	if (min != clk->min_rate || max != clk->max_rate) {
> +		old_min = clk->min_rate;
> +		old_max = clk->max_rate;
>  		clk->min_rate = min;
>  		clk->max_rate = max;
>  		ret = clk_core_set_rate_nolock(clk->core, clk->core->req_rate);
> +		if (ret) {
> +			/* undo changes */
> +			clk->min_rate = old_min;
> +			clk->max_rate = old_max;
> +		}
>  	}
>  
>  	if (clk->protect_count)
Jerome Brunet July 26, 2017, 5:22 p.m. UTC | #2
On Tue, 2017-07-11 at 19:02 -0700, Stephen Boyd wrote:
> On 06/12, Jerome Brunet wrote:
> > Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
> 
> There should be some commit text here describing the problem.
> Also a Fixes: tag and please put this earlier in the series.

Fixes added but as explained, I dropped this patch after thinking about Peter's
observations.

The new candidate patch would be [0]. I suggest we discuss this out of the clock
 protect thread to avoid mixing issues.

[0]: https://github.com/jeromebrunet/linux/commit/235e477f346a9e8d115dda257f9f73
834151bd7f


> 
> > ---
> >  drivers/clk/clk.c | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> > 
> > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> > index d91236e70a04..253f1d3f0971 100644
> > --- a/drivers/clk/clk.c
> > +++ b/drivers/clk/clk.c
> > @@ -1864,6 +1864,7 @@ EXPORT_SYMBOL_GPL(clk_set_rate_protect);
> >  int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long
> > max)
> >  {
> >  	int ret = 0;
> > +	unsigned int old_min, old_max;
> >  
> >  	if (!clk)
> >  		return 0;
> > @@ -1881,9 +1882,16 @@ int clk_set_rate_range(struct clk *clk, unsigned long
> > min, unsigned long max)
> >  		clk_core_rate_unprotect(clk->core);
> >  
> >  	if (min != clk->min_rate || max != clk->max_rate) {
> > +		old_min = clk->min_rate;
> > +		old_max = clk->max_rate;
> >  		clk->min_rate = min;
> >  		clk->max_rate = max;
> >  		ret = clk_core_set_rate_nolock(clk->core, clk->core-
> > >req_rate);
> > +		if (ret) {
> > +			/* undo changes */
> > +			clk->min_rate = old_min;
> > +			clk->max_rate = old_max;
> > +		}
> >  	}
> >  
> >  	if (clk->protect_count)
> 
>
diff mbox

Patch

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index d91236e70a04..253f1d3f0971 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -1864,6 +1864,7 @@  EXPORT_SYMBOL_GPL(clk_set_rate_protect);
 int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max)
 {
 	int ret = 0;
+	unsigned int old_min, old_max;
 
 	if (!clk)
 		return 0;
@@ -1881,9 +1882,16 @@  int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max)
 		clk_core_rate_unprotect(clk->core);
 
 	if (min != clk->min_rate || max != clk->max_rate) {
+		old_min = clk->min_rate;
+		old_max = clk->max_rate;
 		clk->min_rate = min;
 		clk->max_rate = max;
 		ret = clk_core_set_rate_nolock(clk->core, clk->core->req_rate);
+		if (ret) {
+			/* undo changes */
+			clk->min_rate = old_min;
+			clk->max_rate = old_max;
+		}
 	}
 
 	if (clk->protect_count)