[PATCH] pwm: atmel: Make use of dev_err_probe()

Lee Jones lee.jones at linaro.org
Wed Aug 12 04:20:02 EDT 2020


On Wed, 12 Aug 2020, Uwe Kleine-König wrote:

> Add an error message for failure points that currently lack a message
> and convert dev_err to dev_err_probe() which does the right thing for
> -EPROBE_DEFER. Also slightly simplify the error handling.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig at pengutronix.de>
> ---
>  drivers/pwm/pwm-atmel.c | 24 +++++++++++-------------
>  1 file changed, 11 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
> index 6161e7e3e9ac..aa0b36695dc7 100644
> --- a/drivers/pwm/pwm-atmel.c
> +++ b/drivers/pwm/pwm-atmel.c
> @@ -415,17 +415,18 @@ static int atmel_pwm_probe(struct platform_device *pdev)
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>  	atmel_pwm->base = devm_ioremap_resource(&pdev->dev, res);
>  	if (IS_ERR(atmel_pwm->base))
> -		return PTR_ERR(atmel_pwm->base);
> +		return dev_err_probe(&pdev->dev, PTR_ERR(atmel_pwm->base),
> +				     "Failed to remap register space\n");

This is a regression.

devm_ioremap_resource() already emits and error message for !-ENOMEM.

-ENOMEM cases should fail silently.

>  	atmel_pwm->clk = devm_clk_get(&pdev->dev, NULL);
>  	if (IS_ERR(atmel_pwm->clk))
> -		return PTR_ERR(atmel_pwm->clk);
> +		return dev_err_probe(&pdev->dev, PTR_ERR(atmel_pwm->clk),
> +				     "Failed to get clock\n");

Isn't dev_err_probe() only useful for drivers handling -EPROBE_DEFER?

>  	ret = clk_prepare(atmel_pwm->clk);
> -	if (ret) {
> -		dev_err(&pdev->dev, "failed to prepare PWM clock\n");
> -		return ret;
> -	}
> +	if (ret)
> +		return dev_err_probe(&pdev->dev, ret,
> +				     "Failed to prepare PWM clock\n");

As above.

>  	atmel_pwm->chip.dev = &pdev->dev;
>  	atmel_pwm->chip.ops = &atmel_pwm_ops;
> @@ -436,17 +437,14 @@ static int atmel_pwm_probe(struct platform_device *pdev)
>  
>  	ret = pwmchip_add(&atmel_pwm->chip);
>  	if (ret < 0) {
> -		dev_err(&pdev->dev, "failed to add PWM chip %d\n", ret);
> -		goto unprepare_clk;
> +		clk_unprepare(atmel_pwm->clk);
> +		return dev_err_probe(&pdev->dev, ret,
> +				     "Failed to add PWM chip\n");
>  	}
>  
>  	platform_set_drvdata(pdev, atmel_pwm);
>  
> -	return ret;
> -
> -unprepare_clk:
> -	clk_unprepare(atmel_pwm->clk);
> -	return ret;
> +	return 0;
>  }
>  
>  static int atmel_pwm_remove(struct platform_device *pdev)

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



More information about the linux-arm-kernel mailing list