linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: pxa: use devres for the clock struct
@ 2022-08-15  9:19 Bartosz Golaszewski
  2022-08-16 21:08 ` Linus Walleij
  2022-08-19 22:14 ` Andy Shevchenko
  0 siblings, 2 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2022-08-15  9:19 UTC (permalink / raw)
  To: Robert Jarzmik, Linus Walleij
  Cc: linux-gpio, linux-kernel, Bartosz Golaszewski, Hulk Robot, Yuan Can

The clock is never released after probe(). Use devres to not leak
resources.

Reported-by: Hulk Robot <hulkci@huawei.com>
Reported-by: Yuan Can <yuancan@huawei.com>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
 drivers/gpio/gpio-pxa.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
index c7fbfa3ae43b..1198ab0305d0 100644
--- a/drivers/gpio/gpio-pxa.c
+++ b/drivers/gpio/gpio-pxa.c
@@ -661,24 +661,17 @@ static int pxa_gpio_probe(struct platform_device *pdev)
 	if (IS_ERR(gpio_reg_base))
 		return PTR_ERR(gpio_reg_base);
 
-	clk = clk_get(&pdev->dev, NULL);
+	clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(clk)) {
 		dev_err(&pdev->dev, "Error %ld to get gpio clock\n",
 			PTR_ERR(clk));
 		return PTR_ERR(clk);
 	}
-	ret = clk_prepare_enable(clk);
-	if (ret) {
-		clk_put(clk);
-		return ret;
-	}
 
 	/* Initialize GPIO chips */
 	ret = pxa_init_gpio_chip(pchip, pxa_last_gpio + 1, gpio_reg_base);
-	if (ret) {
-		clk_put(clk);
+	if (ret)
 		return ret;
-	}
 
 	/* clear all GPIO edge detects */
 	for_each_gpio_bank(gpio, c, pchip) {
-- 
2.34.1


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

* Re: [PATCH] gpio: pxa: use devres for the clock struct
  2022-08-15  9:19 [PATCH] gpio: pxa: use devres for the clock struct Bartosz Golaszewski
@ 2022-08-16 21:08 ` Linus Walleij
  2022-08-19 22:14 ` Andy Shevchenko
  1 sibling, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2022-08-16 21:08 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Robert Jarzmik, linux-gpio, linux-kernel, Hulk Robot, Yuan Can

On Mon, Aug 15, 2022 at 11:19 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote:

> The clock is never released after probe(). Use devres to not leak
> resources.
>
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Reported-by: Yuan Can <yuancan@huawei.com>
> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

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

* Re: [PATCH] gpio: pxa: use devres for the clock struct
  2022-08-15  9:19 [PATCH] gpio: pxa: use devres for the clock struct Bartosz Golaszewski
  2022-08-16 21:08 ` Linus Walleij
@ 2022-08-19 22:14 ` Andy Shevchenko
  2022-08-26  8:20   ` Linus Walleij
  1 sibling, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2022-08-19 22:14 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Robert Jarzmik, Linus Walleij, open list:GPIO SUBSYSTEM,
	Linux Kernel Mailing List, Hulk Robot, Yuan Can

On Mon, Aug 15, 2022 at 12:26 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>
> The clock is never released after probe(). Use devres to not leak
> resources.

...

> -       clk = clk_get(&pdev->dev, NULL);
> +       clk = devm_clk_get_enabled(&pdev->dev, NULL);
>         if (IS_ERR(clk)) {
>                 dev_err(&pdev->dev, "Error %ld to get gpio clock\n",
>                         PTR_ERR(clk));
>                 return PTR_ERR(clk);

Shouldn't we fix a potential log saturation issue first (by switching
to use dev_err_probe() helper)?

>         }

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH] gpio: pxa: use devres for the clock struct
  2022-08-19 22:14 ` Andy Shevchenko
@ 2022-08-26  8:20   ` Linus Walleij
  2022-08-26 12:18     ` Christophe JAILLET
  0 siblings, 1 reply; 6+ messages in thread
From: Linus Walleij @ 2022-08-26  8:20 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Bartosz Golaszewski, Robert Jarzmik, open list:GPIO SUBSYSTEM,
	Linux Kernel Mailing List, Hulk Robot, Yuan Can

On Sat, Aug 20, 2022 at 12:15 AM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Mon, Aug 15, 2022 at 12:26 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> >
> > The clock is never released after probe(). Use devres to not leak
> > resources.
>
> ...
>
> > -       clk = clk_get(&pdev->dev, NULL);
> > +       clk = devm_clk_get_enabled(&pdev->dev, NULL);
> >         if (IS_ERR(clk)) {
> >                 dev_err(&pdev->dev, "Error %ld to get gpio clock\n",
> >                         PTR_ERR(clk));
> >                 return PTR_ERR(clk);
>
> Shouldn't we fix a potential log saturation issue first (by switching
> to use dev_err_probe() helper)?

Can be a separate patch, the clock mem leak is a bigger problem
IMO so this should be applied first.

Hm isn't it possible to toss the task of fixing a gazillion
dev_err_probe() messages on Cocinelle scripts/coccinelle/? I bet it's something
the kernel janitors could fix all over the place.

Yours,
Linus Walleij

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

* Re: [PATCH] gpio: pxa: use devres for the clock struct
  2022-08-26  8:20   ` Linus Walleij
@ 2022-08-26 12:18     ` Christophe JAILLET
  2022-08-27 12:35       ` Marion & Christophe JAILLET
  0 siblings, 1 reply; 6+ messages in thread
From: Christophe JAILLET @ 2022-08-26 12:18 UTC (permalink / raw)
  To: Linus Walleij, Andy Shevchenko
  Cc: Bartosz Golaszewski, Robert Jarzmik, open list:GPIO SUBSYSTEM,
	Linux Kernel Mailing List, Hulk Robot, Yuan Can, Kernel Janitors

Le 26/08/2022 à 10:20, Linus Walleij a écrit :
> On Sat, Aug 20, 2022 at 12:15 AM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
>> On Mon, Aug 15, 2022 at 12:26 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>>>
>>> The clock is never released after probe(). Use devres to not leak
>>> resources.
>>
>> ...
>>
>>> -       clk = clk_get(&pdev->dev, NULL);
>>> +       clk = devm_clk_get_enabled(&pdev->dev, NULL);
>>>          if (IS_ERR(clk)) {
>>>                  dev_err(&pdev->dev, "Error %ld to get gpio clock\n",
>>>                          PTR_ERR(clk));
>>>                  return PTR_ERR(clk);
>>
>> Shouldn't we fix a potential log saturation issue first (by switching
>> to use dev_err_probe() helper)?
> 
> Can be a separate patch, the clock mem leak is a bigger problem
> IMO so this should be applied first.
> 
> Hm isn't it possible to toss the task of fixing a gazillion
> dev_err_probe() messages on Cocinelle scripts/coccinelle/? I bet it's something
> the kernel janitors could fix all over the place.
> 
> Yours,
> Linus Walleij
> 

Not perfect and certainly incomplete, but gives an idea:


@@
expression x, dev, e, str;
@@
(
	x = devm_clk_get(dev, e);
|
	x = clk_get(dev, e);
)
-	if (IS_ERR(x)) {
-		dev_err(dev, str);
-		return PTR_ERR(x);
-	}
+	if (IS_ERR(x))
+		return dev_err_probe(dev, PTR_ERR(x), str);

// This rule only: 291 files changed, 1233 insertions(+), 1634 deletions(-)


// The output of this rule needs to be adjusted to fix the 'str'. The
// error code and related text have to be manually removed
@@
expression x, dev, e, str;
@@
(
	x = devm_clk_get(dev, e);
|
	x = clk_get(dev, e);
)
-	if (IS_ERR(x)) {
-		dev_err(dev, str, PTR_ERR(x));
-		return PTR_ERR(x);
-	}
+	if (IS_ERR(x))
+		return dev_err_probe(dev, PTR_ERR(x), str);

// Both rules: 316 files changed, 1321 insertions(+), 1774 deletions(-)

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

* Re: [PATCH] gpio: pxa: use devres for the clock struct
  2022-08-26 12:18     ` Christophe JAILLET
@ 2022-08-27 12:35       ` Marion & Christophe JAILLET
  0 siblings, 0 replies; 6+ messages in thread
From: Marion & Christophe JAILLET @ 2022-08-27 12:35 UTC (permalink / raw)
  To: Linus Walleij, Andy Shevchenko
  Cc: Bartosz Golaszewski, Robert Jarzmik, open list:GPIO SUBSYSTEM,
	Linux Kernel Mailing List, Hulk Robot, Yuan Can, Kernel Janitors



Le 26/08/2022 à 14:18, Christophe JAILLET a écrit :
> Le 26/08/2022 à 10:20, Linus Walleij a écrit :
>> On Sat, Aug 20, 2022 at 12:15 AM Andy Shevchenko
>> <andy.shevchenko@gmail.com> wrote:
>>> On Mon, Aug 15, 2022 at 12:26 PM Bartosz Golaszewski <brgl@bgdev.pl> 
>>> wrote:
>>>>
>>>> The clock is never released after probe(). Use devres to not leak
>>>> resources.
>>>
>>> ...
>>>
>>>> -       clk = clk_get(&pdev->dev, NULL);
>>>> +       clk = devm_clk_get_enabled(&pdev->dev, NULL);
>>>>          if (IS_ERR(clk)) {
>>>>                  dev_err(&pdev->dev, "Error %ld to get gpio clock\n",
>>>>                          PTR_ERR(clk));
>>>>                  return PTR_ERR(clk);
>>>
>>> Shouldn't we fix a potential log saturation issue first (by switching
>>> to use dev_err_probe() helper)?
>>
>> Can be a separate patch, the clock mem leak is a bigger problem
>> IMO so this should be applied first.
>>
>> Hm isn't it possible to toss the task of fixing a gazillion
>> dev_err_probe() messages on Cocinelle scripts/coccinelle/? I bet it's 
>> something
>> the kernel janitors could fix all over the place.
>>
>> Yours,
>> Linus Walleij
>>
>
> // Both rules: 316 files changed, 1321 insertions(+), 1774 deletions(-)
> 


With an updated script, I spot:
    503 files changed, 1962 insertions(+), 2622 deletions(-)

(and 150-200 still needs some manual check or script adjustment)


Does this really make sense to send SO many patches for it?

If yes, should it be done on a per-system basis, or by driver basis?

CJ

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

end of thread, other threads:[~2022-08-27 12:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-15  9:19 [PATCH] gpio: pxa: use devres for the clock struct Bartosz Golaszewski
2022-08-16 21:08 ` Linus Walleij
2022-08-19 22:14 ` Andy Shevchenko
2022-08-26  8:20   ` Linus Walleij
2022-08-26 12:18     ` Christophe JAILLET
2022-08-27 12:35       ` Marion & Christophe JAILLET

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).