* [PATCH 1/2] pwm: pwm-mediatek: Simplify error handling with dev_err_probe()
@ 2022-02-14 11:30 AngeloGioacchino Del Regno
2022-02-14 11:30 ` [PATCH 2/2] pwm: pwm-mediatek: Allocate clk_pwms with devm_kmalloc_array AngeloGioacchino Del Regno
2022-02-14 13:48 ` [PATCH 1/2] pwm: pwm-mediatek: Simplify error handling with dev_err_probe() Uwe Kleine-König
0 siblings, 2 replies; 4+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-02-14 11:30 UTC (permalink / raw)
To: thierry.reding
Cc: u.kleine-koenig, lee.jones, matthias.bgg, linux-pwm,
linux-kernel, linux-arm-kernel, linux-mediatek, kernel,
AngeloGioacchino Del Regno
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");
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;
}
--
2.33.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] pwm: pwm-mediatek: Allocate clk_pwms with devm_kmalloc_array
2022-02-14 11:30 [PATCH 1/2] pwm: pwm-mediatek: Simplify error handling with dev_err_probe() AngeloGioacchino Del Regno
@ 2022-02-14 11:30 ` AngeloGioacchino Del Regno
2022-02-14 13:48 ` [PATCH 1/2] pwm: pwm-mediatek: Simplify error handling with dev_err_probe() Uwe Kleine-König
1 sibling, 0 replies; 4+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-02-14 11:30 UTC (permalink / raw)
To: thierry.reding
Cc: u.kleine-koenig, lee.jones, matthias.bgg, linux-pwm,
linux-kernel, linux-arm-kernel, linux-mediatek, kernel,
AngeloGioacchino Del Regno
Switch from devm_kcalloc to devm_kmalloc_array when allocating clk_pwms,
as this structure is being filled right after allocating it, hence
there is no need to zero it out beforehand.
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
drivers/pwm/pwm-mediatek.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c
index c7d5ca09a684..6b39f3d69e41 100644
--- a/drivers/pwm/pwm-mediatek.c
+++ b/drivers/pwm/pwm-mediatek.c
@@ -221,7 +221,7 @@ static int pwm_mediatek_probe(struct platform_device *pdev)
if (IS_ERR(pc->regs))
return PTR_ERR(pc->regs);
- pc->clk_pwms = devm_kcalloc(&pdev->dev, pc->soc->num_pwms,
+ pc->clk_pwms = devm_kmalloc_array(&pdev->dev, pc->soc->num_pwms,
sizeof(*pc->clk_pwms), GFP_KERNEL);
if (!pc->clk_pwms)
return -ENOMEM;
--
2.33.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] pwm: pwm-mediatek: Simplify error handling with dev_err_probe()
2022-02-14 11:30 [PATCH 1/2] pwm: pwm-mediatek: Simplify error handling with dev_err_probe() AngeloGioacchino Del Regno
2022-02-14 11:30 ` [PATCH 2/2] pwm: pwm-mediatek: Allocate clk_pwms with devm_kmalloc_array AngeloGioacchino Del Regno
@ 2022-02-14 13:48 ` Uwe Kleine-König
2022-02-14 13:50 ` AngeloGioacchino Del Regno
1 sibling, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2022-02-14 13:48 UTC (permalink / raw)
To: AngeloGioacchino Del Regno
Cc: thierry.reding, lee.jones, matthias.bgg, linux-pwm, linux-kernel,
linux-arm-kernel, linux-mediatek, kernel
[-- Attachment #1: Type: text/plain, Size: 1351 bytes --]
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
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] pwm: pwm-mediatek: Simplify error handling with dev_err_probe()
2022-02-14 13:48 ` [PATCH 1/2] pwm: pwm-mediatek: Simplify error handling with dev_err_probe() Uwe Kleine-König
@ 2022-02-14 13:50 ` AngeloGioacchino Del Regno
0 siblings, 0 replies; 4+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-02-14 13:50 UTC (permalink / raw)
To: Uwe Kleine-König
Cc: thierry.reding, lee.jones, matthias.bgg, linux-pwm, linux-kernel,
linux-arm-kernel, linux-mediatek, kernel
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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-02-14 13:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-14 11:30 [PATCH 1/2] pwm: pwm-mediatek: Simplify error handling with dev_err_probe() AngeloGioacchino Del Regno
2022-02-14 11:30 ` [PATCH 2/2] pwm: pwm-mediatek: Allocate clk_pwms with devm_kmalloc_array AngeloGioacchino Del Regno
2022-02-14 13:48 ` [PATCH 1/2] pwm: pwm-mediatek: Simplify error handling with dev_err_probe() Uwe Kleine-König
2022-02-14 13:50 ` AngeloGioacchino Del Regno
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).