linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: adc: stm32-adc: Remove redundant null check before clk_prepare_enable/clk_disable_unprepare
@ 2020-12-18  9:35 Xu Wang
  2020-12-18 14:32 ` Fabrice Gasnier
  0 siblings, 1 reply; 3+ messages in thread
From: Xu Wang @ 2020-12-18  9:35 UTC (permalink / raw)
  To: jic23, lars, pmeerw, mcoquelin.stm32, alexandre.torgue,
	fabrice.gasnier, krzk, andy.shevchenko, olivier.moysan,
	etienne.carriere, alexandru.ardelean, peter.ujfalusi, linux-iio,
	linux-stm32, linux-arm-kernel
  Cc: linux-kernel

Because clk_prepare_enable() and clk_disable_unprepare() already checked
NULL clock parameter, so the additional checks are unnecessary, just
remove them.

Signed-off-by: Xu Wang <vulab@iscas.ac.cn>
---
 drivers/iio/adc/stm32-adc-core.c | 29 +++++++++++------------------
 drivers/iio/adc/stm32-adc.c      | 14 +++++---------
 2 files changed, 16 insertions(+), 27 deletions(-)

diff --git a/drivers/iio/adc/stm32-adc-core.c b/drivers/iio/adc/stm32-adc-core.c
index 9d1ad6e38e85..c088cb990193 100644
--- a/drivers/iio/adc/stm32-adc-core.c
+++ b/drivers/iio/adc/stm32-adc-core.c
@@ -535,20 +535,16 @@ static int stm32_adc_core_hw_start(struct device *dev)
 		goto err_switches_dis;
 	}
 
-	if (priv->bclk) {
-		ret = clk_prepare_enable(priv->bclk);
-		if (ret < 0) {
-			dev_err(dev, "bus clk enable failed\n");
-			goto err_regulator_disable;
-		}
+	ret = clk_prepare_enable(priv->bclk);
+	if (ret < 0) {
+		dev_err(dev, "bus clk enable failed\n");
+		goto err_regulator_disable;
 	}
 
-	if (priv->aclk) {
-		ret = clk_prepare_enable(priv->aclk);
-		if (ret < 0) {
-			dev_err(dev, "adc clk enable failed\n");
-			goto err_bclk_disable;
-		}
+	ret = clk_prepare_enable(priv->aclk);
+	if (ret < 0) {
+		dev_err(dev, "adc clk enable failed\n");
+		goto err_bclk_disable;
 	}
 
 	writel_relaxed(priv->ccr_bak, priv->common.base + priv->cfg->regs->ccr);
@@ -556,8 +552,7 @@ static int stm32_adc_core_hw_start(struct device *dev)
 	return 0;
 
 err_bclk_disable:
-	if (priv->bclk)
-		clk_disable_unprepare(priv->bclk);
+	clk_disable_unprepare(priv->bclk);
 err_regulator_disable:
 	regulator_disable(priv->vref);
 err_switches_dis:
@@ -575,10 +570,8 @@ static void stm32_adc_core_hw_stop(struct device *dev)
 
 	/* Backup CCR that may be lost (depends on power state to achieve) */
 	priv->ccr_bak = readl_relaxed(priv->common.base + priv->cfg->regs->ccr);
-	if (priv->aclk)
-		clk_disable_unprepare(priv->aclk);
-	if (priv->bclk)
-		clk_disable_unprepare(priv->bclk);
+	clk_disable_unprepare(priv->aclk);
+	clk_disable_unprepare(priv->bclk);
 	regulator_disable(priv->vref);
 	stm32_adc_core_switches_supply_dis(priv);
 	regulator_disable(priv->vdda);
diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
index c067c994dae2..f7c53cea509a 100644
--- a/drivers/iio/adc/stm32-adc.c
+++ b/drivers/iio/adc/stm32-adc.c
@@ -546,8 +546,7 @@ static int stm32_adc_hw_stop(struct device *dev)
 	if (adc->cfg->unprepare)
 		adc->cfg->unprepare(indio_dev);
 
-	if (adc->clk)
-		clk_disable_unprepare(adc->clk);
+	clk_disable_unprepare(adc->clk);
 
 	return 0;
 }
@@ -558,11 +557,9 @@ static int stm32_adc_hw_start(struct device *dev)
 	struct stm32_adc *adc = iio_priv(indio_dev);
 	int ret;
 
-	if (adc->clk) {
-		ret = clk_prepare_enable(adc->clk);
-		if (ret)
-			return ret;
-	}
+	ret = clk_prepare_enable(adc->clk);
+	if (ret)
+		return ret;
 
 	stm32_adc_set_res(adc);
 
@@ -575,8 +572,7 @@ static int stm32_adc_hw_start(struct device *dev)
 	return 0;
 
 err_clk_dis:
-	if (adc->clk)
-		clk_disable_unprepare(adc->clk);
+	clk_disable_unprepare(adc->clk);
 
 	return ret;
 }
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: adc: stm32-adc: Remove redundant null check before clk_prepare_enable/clk_disable_unprepare
  2020-12-18  9:35 [PATCH] iio: adc: stm32-adc: Remove redundant null check before clk_prepare_enable/clk_disable_unprepare Xu Wang
@ 2020-12-18 14:32 ` Fabrice Gasnier
  2020-12-29 17:14   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Fabrice Gasnier @ 2020-12-18 14:32 UTC (permalink / raw)
  To: Xu Wang, jic23, lars, pmeerw, mcoquelin.stm32, alexandre.torgue,
	krzk, andy.shevchenko, olivier.moysan, etienne.carriere,
	alexandru.ardelean, peter.ujfalusi, linux-iio, linux-stm32,
	linux-arm-kernel
  Cc: linux-kernel

On 12/18/20 10:35 AM, Xu Wang wrote:
> Because clk_prepare_enable() and clk_disable_unprepare() already checked
> NULL clock parameter, so the additional checks are unnecessary, just
> remove them.
> 
> Signed-off-by: Xu Wang <vulab@iscas.ac.cn>
> ---
>  drivers/iio/adc/stm32-adc-core.c | 29 +++++++++++------------------
>  drivers/iio/adc/stm32-adc.c      | 14 +++++---------
>  2 files changed, 16 insertions(+), 27 deletions(-)

Hi Xu,

Acked-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>

Thanks for your patch,
Best Regards,
Fabrice

> 
> diff --git a/drivers/iio/adc/stm32-adc-core.c b/drivers/iio/adc/stm32-adc-core.c
> index 9d1ad6e38e85..c088cb990193 100644
> --- a/drivers/iio/adc/stm32-adc-core.c
> +++ b/drivers/iio/adc/stm32-adc-core.c
> @@ -535,20 +535,16 @@ static int stm32_adc_core_hw_start(struct device *dev)
>  		goto err_switches_dis;
>  	}
>  
> -	if (priv->bclk) {
> -		ret = clk_prepare_enable(priv->bclk);
> -		if (ret < 0) {
> -			dev_err(dev, "bus clk enable failed\n");
> -			goto err_regulator_disable;
> -		}
> +	ret = clk_prepare_enable(priv->bclk);
> +	if (ret < 0) {
> +		dev_err(dev, "bus clk enable failed\n");
> +		goto err_regulator_disable;
>  	}
>  
> -	if (priv->aclk) {
> -		ret = clk_prepare_enable(priv->aclk);
> -		if (ret < 0) {
> -			dev_err(dev, "adc clk enable failed\n");
> -			goto err_bclk_disable;
> -		}
> +	ret = clk_prepare_enable(priv->aclk);
> +	if (ret < 0) {
> +		dev_err(dev, "adc clk enable failed\n");
> +		goto err_bclk_disable;
>  	}
>  
>  	writel_relaxed(priv->ccr_bak, priv->common.base + priv->cfg->regs->ccr);
> @@ -556,8 +552,7 @@ static int stm32_adc_core_hw_start(struct device *dev)
>  	return 0;
>  
>  err_bclk_disable:
> -	if (priv->bclk)
> -		clk_disable_unprepare(priv->bclk);
> +	clk_disable_unprepare(priv->bclk);
>  err_regulator_disable:
>  	regulator_disable(priv->vref);
>  err_switches_dis:
> @@ -575,10 +570,8 @@ static void stm32_adc_core_hw_stop(struct device *dev)
>  
>  	/* Backup CCR that may be lost (depends on power state to achieve) */
>  	priv->ccr_bak = readl_relaxed(priv->common.base + priv->cfg->regs->ccr);
> -	if (priv->aclk)
> -		clk_disable_unprepare(priv->aclk);
> -	if (priv->bclk)
> -		clk_disable_unprepare(priv->bclk);
> +	clk_disable_unprepare(priv->aclk);
> +	clk_disable_unprepare(priv->bclk);
>  	regulator_disable(priv->vref);
>  	stm32_adc_core_switches_supply_dis(priv);
>  	regulator_disable(priv->vdda);
> diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
> index c067c994dae2..f7c53cea509a 100644
> --- a/drivers/iio/adc/stm32-adc.c
> +++ b/drivers/iio/adc/stm32-adc.c
> @@ -546,8 +546,7 @@ static int stm32_adc_hw_stop(struct device *dev)
>  	if (adc->cfg->unprepare)
>  		adc->cfg->unprepare(indio_dev);
>  
> -	if (adc->clk)
> -		clk_disable_unprepare(adc->clk);
> +	clk_disable_unprepare(adc->clk);
>  
>  	return 0;
>  }
> @@ -558,11 +557,9 @@ static int stm32_adc_hw_start(struct device *dev)
>  	struct stm32_adc *adc = iio_priv(indio_dev);
>  	int ret;
>  
> -	if (adc->clk) {
> -		ret = clk_prepare_enable(adc->clk);
> -		if (ret)
> -			return ret;
> -	}
> +	ret = clk_prepare_enable(adc->clk);
> +	if (ret)
> +		return ret;
>  
>  	stm32_adc_set_res(adc);
>  
> @@ -575,8 +572,7 @@ static int stm32_adc_hw_start(struct device *dev)
>  	return 0;
>  
>  err_clk_dis:
> -	if (adc->clk)
> -		clk_disable_unprepare(adc->clk);
> +	clk_disable_unprepare(adc->clk);
>  
>  	return ret;
>  }
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: adc: stm32-adc: Remove redundant null check before clk_prepare_enable/clk_disable_unprepare
  2020-12-18 14:32 ` Fabrice Gasnier
@ 2020-12-29 17:14   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2020-12-29 17:14 UTC (permalink / raw)
  To: Fabrice Gasnier
  Cc: Xu Wang, lars, pmeerw, mcoquelin.stm32, alexandre.torgue, krzk,
	andy.shevchenko, olivier.moysan, etienne.carriere,
	alexandru.ardelean, peter.ujfalusi, linux-iio, linux-stm32,
	linux-arm-kernel, linux-kernel

On Fri, 18 Dec 2020 15:32:32 +0100
Fabrice Gasnier <fabrice.gasnier@foss.st.com> wrote:

> On 12/18/20 10:35 AM, Xu Wang wrote:
> > Because clk_prepare_enable() and clk_disable_unprepare() already checked
> > NULL clock parameter, so the additional checks are unnecessary, just
> > remove them.
> > 
> > Signed-off-by: Xu Wang <vulab@iscas.ac.cn>
> > ---
> >  drivers/iio/adc/stm32-adc-core.c | 29 +++++++++++------------------
> >  drivers/iio/adc/stm32-adc.c      | 14 +++++---------
> >  2 files changed, 16 insertions(+), 27 deletions(-)  
> 
> Hi Xu,
> 
> Acked-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Applied,

thanks,

Jonathan

> 
> Thanks for your patch,
> Best Regards,
> Fabrice
> 
> > 
> > diff --git a/drivers/iio/adc/stm32-adc-core.c b/drivers/iio/adc/stm32-adc-core.c
> > index 9d1ad6e38e85..c088cb990193 100644
> > --- a/drivers/iio/adc/stm32-adc-core.c
> > +++ b/drivers/iio/adc/stm32-adc-core.c
> > @@ -535,20 +535,16 @@ static int stm32_adc_core_hw_start(struct device *dev)
> >  		goto err_switches_dis;
> >  	}
> >  
> > -	if (priv->bclk) {
> > -		ret = clk_prepare_enable(priv->bclk);
> > -		if (ret < 0) {
> > -			dev_err(dev, "bus clk enable failed\n");
> > -			goto err_regulator_disable;
> > -		}
> > +	ret = clk_prepare_enable(priv->bclk);
> > +	if (ret < 0) {
> > +		dev_err(dev, "bus clk enable failed\n");
> > +		goto err_regulator_disable;
> >  	}
> >  
> > -	if (priv->aclk) {
> > -		ret = clk_prepare_enable(priv->aclk);
> > -		if (ret < 0) {
> > -			dev_err(dev, "adc clk enable failed\n");
> > -			goto err_bclk_disable;
> > -		}
> > +	ret = clk_prepare_enable(priv->aclk);
> > +	if (ret < 0) {
> > +		dev_err(dev, "adc clk enable failed\n");
> > +		goto err_bclk_disable;
> >  	}
> >  
> >  	writel_relaxed(priv->ccr_bak, priv->common.base + priv->cfg->regs->ccr);
> > @@ -556,8 +552,7 @@ static int stm32_adc_core_hw_start(struct device *dev)
> >  	return 0;
> >  
> >  err_bclk_disable:
> > -	if (priv->bclk)
> > -		clk_disable_unprepare(priv->bclk);
> > +	clk_disable_unprepare(priv->bclk);
> >  err_regulator_disable:
> >  	regulator_disable(priv->vref);
> >  err_switches_dis:
> > @@ -575,10 +570,8 @@ static void stm32_adc_core_hw_stop(struct device *dev)
> >  
> >  	/* Backup CCR that may be lost (depends on power state to achieve) */
> >  	priv->ccr_bak = readl_relaxed(priv->common.base + priv->cfg->regs->ccr);
> > -	if (priv->aclk)
> > -		clk_disable_unprepare(priv->aclk);
> > -	if (priv->bclk)
> > -		clk_disable_unprepare(priv->bclk);
> > +	clk_disable_unprepare(priv->aclk);
> > +	clk_disable_unprepare(priv->bclk);
> >  	regulator_disable(priv->vref);
> >  	stm32_adc_core_switches_supply_dis(priv);
> >  	regulator_disable(priv->vdda);
> > diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
> > index c067c994dae2..f7c53cea509a 100644
> > --- a/drivers/iio/adc/stm32-adc.c
> > +++ b/drivers/iio/adc/stm32-adc.c
> > @@ -546,8 +546,7 @@ static int stm32_adc_hw_stop(struct device *dev)
> >  	if (adc->cfg->unprepare)
> >  		adc->cfg->unprepare(indio_dev);
> >  
> > -	if (adc->clk)
> > -		clk_disable_unprepare(adc->clk);
> > +	clk_disable_unprepare(adc->clk);
> >  
> >  	return 0;
> >  }
> > @@ -558,11 +557,9 @@ static int stm32_adc_hw_start(struct device *dev)
> >  	struct stm32_adc *adc = iio_priv(indio_dev);
> >  	int ret;
> >  
> > -	if (adc->clk) {
> > -		ret = clk_prepare_enable(adc->clk);
> > -		if (ret)
> > -			return ret;
> > -	}
> > +	ret = clk_prepare_enable(adc->clk);
> > +	if (ret)
> > +		return ret;
> >  
> >  	stm32_adc_set_res(adc);
> >  
> > @@ -575,8 +572,7 @@ static int stm32_adc_hw_start(struct device *dev)
> >  	return 0;
> >  
> >  err_clk_dis:
> > -	if (adc->clk)
> > -		clk_disable_unprepare(adc->clk);
> > +	clk_disable_unprepare(adc->clk);
> >  
> >  	return ret;
> >  }
> >   


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-29 17:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-18  9:35 [PATCH] iio: adc: stm32-adc: Remove redundant null check before clk_prepare_enable/clk_disable_unprepare Xu Wang
2020-12-18 14:32 ` Fabrice Gasnier
2020-12-29 17:14   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).