diff mbox series

[1/2] pwm: pwm-mediatek: Simplify error handling with dev_err_probe()

Message ID 20220214113038.79130-1-angelogioacchino.delregno@collabora.com (mailing list archive)
State New, archived
Headers show
Series [1/2] pwm: pwm-mediatek: Simplify error handling with dev_err_probe() | expand

Commit Message

AngeloGioacchino Del Regno Feb. 14, 2022, 11:30 a.m. UTC
Use dev_err_probe() to simplify handling errors in pwm_mediatek_probe().

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 drivers/pwm/pwm-mediatek.c | 30 +++++++++++-------------------
 1 file changed, 11 insertions(+), 19 deletions(-)

Comments

Uwe Kleine-König Feb. 14, 2022, 1:48 p.m. UTC | #1
On Mon, Feb 14, 2022 at 12:30:37PM +0100, AngeloGioacchino Del Regno wrote:
> Use dev_err_probe() to simplify handling errors in pwm_mediatek_probe().
> 
> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> ---
>  drivers/pwm/pwm-mediatek.c | 30 +++++++++++-------------------
>  1 file changed, 11 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c
> index 0d4dd80e9f07..c7d5ca09a684 100644
> --- a/drivers/pwm/pwm-mediatek.c
> +++ b/drivers/pwm/pwm-mediatek.c
> @@ -227,18 +227,14 @@ static int pwm_mediatek_probe(struct platform_device *pdev)
>  		return -ENOMEM;
>  
>  	pc->clk_top = devm_clk_get(&pdev->dev, "top");
> -	if (IS_ERR(pc->clk_top)) {
> -		dev_err(&pdev->dev, "clock: top fail: %ld\n",
> -			PTR_ERR(pc->clk_top));
> -		return PTR_ERR(pc->clk_top);
> -	}
> +	if (IS_ERR(pc->clk_top))
> +		return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk_top),
> +				     "clock: top failed\n");

The change looks straight forward. I wonder if we should improve the
error message on this occasion. E.g.

	"Failed to get top clock\n"

? Ditto below.

Best regards
Uwe
AngeloGioacchino Del Regno Feb. 14, 2022, 1:50 p.m. UTC | #2
Il 14/02/22 14:48, Uwe Kleine-König ha scritto:
> On Mon, Feb 14, 2022 at 12:30:37PM +0100, AngeloGioacchino Del Regno wrote:
>> Use dev_err_probe() to simplify handling errors in pwm_mediatek_probe().
>>
>> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
>> ---
>>   drivers/pwm/pwm-mediatek.c | 30 +++++++++++-------------------
>>   1 file changed, 11 insertions(+), 19 deletions(-)
>>
>> diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c
>> index 0d4dd80e9f07..c7d5ca09a684 100644
>> --- a/drivers/pwm/pwm-mediatek.c
>> +++ b/drivers/pwm/pwm-mediatek.c
>> @@ -227,18 +227,14 @@ static int pwm_mediatek_probe(struct platform_device *pdev)
>>   		return -ENOMEM;
>>   
>>   	pc->clk_top = devm_clk_get(&pdev->dev, "top");
>> -	if (IS_ERR(pc->clk_top)) {
>> -		dev_err(&pdev->dev, "clock: top fail: %ld\n",
>> -			PTR_ERR(pc->clk_top));
>> -		return PTR_ERR(pc->clk_top);
>> -	}
>> +	if (IS_ERR(pc->clk_top))
>> +		return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk_top),
>> +				     "clock: top failed\n");
> 
> The change looks straight forward. I wonder if we should improve the
> error message on this occasion. E.g.
> 
> 	"Failed to get top clock\n"
> 

I can push another commit on top that improves the messages, if desired!

Regards,
Angelo

> ? Ditto below.
> 
> Best regards
> Uwe
>
diff mbox series

Patch

diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c
index 0d4dd80e9f07..c7d5ca09a684 100644
--- a/drivers/pwm/pwm-mediatek.c
+++ b/drivers/pwm/pwm-mediatek.c
@@ -227,18 +227,14 @@  static int pwm_mediatek_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	pc->clk_top = devm_clk_get(&pdev->dev, "top");
-	if (IS_ERR(pc->clk_top)) {
-		dev_err(&pdev->dev, "clock: top fail: %ld\n",
-			PTR_ERR(pc->clk_top));
-		return PTR_ERR(pc->clk_top);
-	}
+	if (IS_ERR(pc->clk_top))
+		return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk_top),
+				     "clock: top failed\n");
 
 	pc->clk_main = devm_clk_get(&pdev->dev, "main");
-	if (IS_ERR(pc->clk_main)) {
-		dev_err(&pdev->dev, "clock: main fail: %ld\n",
-			PTR_ERR(pc->clk_main));
-		return PTR_ERR(pc->clk_main);
-	}
+	if (IS_ERR(pc->clk_main))
+		return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk_main),
+				     "clock: main failed\n");
 
 	for (i = 0; i < pc->soc->num_pwms; i++) {
 		char name[8];
@@ -246,11 +242,9 @@  static int pwm_mediatek_probe(struct platform_device *pdev)
 		snprintf(name, sizeof(name), "pwm%d", i + 1);
 
 		pc->clk_pwms[i] = devm_clk_get(&pdev->dev, name);
-		if (IS_ERR(pc->clk_pwms[i])) {
-			dev_err(&pdev->dev, "clock: %s fail: %ld\n",
-				name, PTR_ERR(pc->clk_pwms[i]));
-			return PTR_ERR(pc->clk_pwms[i]);
-		}
+		if (IS_ERR(pc->clk_pwms[i]))
+			return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk_pwms[i]),
+					     "clock: %s failed\n", name);
 	}
 
 	pc->chip.dev = &pdev->dev;
@@ -258,10 +252,8 @@  static int pwm_mediatek_probe(struct platform_device *pdev)
 	pc->chip.npwm = pc->soc->num_pwms;
 
 	ret = devm_pwmchip_add(&pdev->dev, &pc->chip);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret);
-		return ret;
-	}
+	if (ret < 0)
+		return dev_err_probe(&pdev->dev, ret, "pwmchip_add() failed\n");
 
 	return 0;
 }