public inbox for linux-pwm@vger.kernel.org
 help / color / mirror / Atom feed
From: Lee Jones <lee.jones@linaro.org>
To: Thierry Reding <thierry.reding@gmail.com>
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Ajit Pal Singh" <ajitpal.singh@st.com>,
	linux-pwm@vger.kernel.org
Subject: Re: [PATCH 1/2] pwm: sti: Avoid conditional gotos
Date: Thu, 12 Nov 2020 08:59:10 +0000	[thread overview]
Message-ID: <20201112085910.GT2063125@dell> (raw)
In-Reply-To: <20201111191449.409402-1-thierry.reding@gmail.com>

On Wed, 11 Nov 2020, Thierry Reding wrote:

> Using gotos for conditional code complicates this code significantly.
> Convert the code to simple conditional blocks to increase readability.
> 
> Suggested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
> ---
>  drivers/pwm/pwm-sti.c | 53 ++++++++++++++++++++-----------------------
>  1 file changed, 24 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c
> index a1392255955f..c6c82724d327 100644
> --- a/drivers/pwm/pwm-sti.c
> +++ b/drivers/pwm/pwm-sti.c
> @@ -590,48 +590,43 @@ static int sti_pwm_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> -	if (!cdata->pwm_num_devs)
> -		goto skip_pwm;
> -
> -	pc->pwm_clk = of_clk_get_by_name(dev->of_node, "pwm");
> -	if (IS_ERR(pc->pwm_clk)) {
> -		dev_err(dev, "failed to get PWM clock\n");
> -		return PTR_ERR(pc->pwm_clk);
> -	}
> +	if (cdata->pwm_num_devs) {
> +		pc->pwm_clk = of_clk_get_by_name(dev->of_node, "pwm");
> +		if (IS_ERR(pc->pwm_clk)) {
> +			dev_err(dev, "failed to get PWM clock\n");
> +			return PTR_ERR(pc->pwm_clk);
> +		}
>  
> -	ret = clk_prepare(pc->pwm_clk);
> -	if (ret) {
> -		dev_err(dev, "failed to prepare clock\n");
> -		goto put_pwm_clk;
> +		ret = clk_prepare(pc->pwm_clk);
> +		if (ret) {
> +			dev_err(dev, "failed to prepare clock\n");
> +			goto put_pwm_clk;
> +		}
>  	}
>  
> -skip_pwm:
> -	if (!cdata->cpt_num_devs)
> -		goto skip_cpt;
> -
> -	pc->cpt_clk = of_clk_get_by_name(dev->of_node, "capture");
> -	if (IS_ERR(pc->cpt_clk)) {
> -		dev_err(dev, "failed to get PWM capture clock\n");
> -		ret = PTR_ERR(pc->cpt_clk);
> -		goto unprepare_pwm_clk;
> -	}
> +	if (cdata->cpt_num_devs) {
> +		pc->cpt_clk = of_clk_get_by_name(dev->of_node, "capture");
> +		if (IS_ERR(pc->cpt_clk)) {
> +			dev_err(dev, "failed to get PWM capture clock\n");
> +			ret = PTR_ERR(pc->cpt_clk);
> +			goto unprepare_pwm_clk;
> +		}
>  
> -	ret = clk_prepare(pc->cpt_clk);
> -	if (ret) {
> -		dev_err(dev, "failed to prepare clock\n");
> -		goto put_cpt_clk;
> +		ret = clk_prepare(pc->cpt_clk);
> +		if (ret) {
> +			dev_err(dev, "failed to prepare clock\n");
> +			goto put_cpt_clk;
> +		}
>  	}
>  
> -skip_cpt:
>  	pc->chip.dev = dev;
>  	pc->chip.ops = &sti_pwm_ops;
>  	pc->chip.base = -1;
>  	pc->chip.npwm = pc->cdata->pwm_num_devs;
>  
>  	ret = pwmchip_add(&pc->chip);
> -	if (ret < 0) {
> +	if (ret < 0)
>  		goto unprepare_cpt_clk;
> -	}

Sneaky!

Acked-by: Lee Jones <lee.jones@linaro.org>

-- 
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog

      parent reply	other threads:[~2020-11-12  8:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-11 19:14 [PATCH 1/2] pwm: sti: Avoid conditional gotos Thierry Reding
2020-11-11 19:14 ` [PATCH 2/2] pwm: sti: Remove unnecessary blank line Thierry Reding
2020-11-12  8:59   ` Lee Jones
2020-11-12 11:04   ` Uwe Kleine-König
2020-11-12  7:56 ` [PATCH 1/2] pwm: sti: Avoid conditional gotos Uwe Kleine-König
2020-11-12  8:59 ` Lee Jones [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201112085910.GT2063125@dell \
    --to=lee.jones@linaro.org \
    --cc=ajitpal.singh@st.com \
    --cc=linux-pwm@vger.kernel.org \
    --cc=thierry.reding@gmail.com \
    --cc=u.kleine-koenig@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox