2023-07-19 11:50:34

by Bartosz Golaszewski

[permalink] [raw]
Subject: [PATCH] gpio: mvebu: fix irq domain leak

From: Bartosz Golaszewski <[email protected]>

Uwe Kleine-König pointed out we still have one resource leak in the mvebu
driver triggered on driver detach. Let's address it with a custom devm
action.

Fixes: 812d47889a8e ("gpio/mvebu: Use irq_domain_add_linear")
Signed-off-by: Bartosz Golaszewski <[email protected]>
---
drivers/gpio/gpio-mvebu.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index a35958e7adf6..67497116ce27 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -1112,6 +1112,13 @@ static int mvebu_gpio_probe_syscon(struct platform_device *pdev,
return 0;
}

+static void mvebu_gpio_remove_irq_domain(void *data)
+{
+ struct irq_domain *domain = data;
+
+ irq_domain_remove(domain);
+}
+
static int mvebu_gpio_probe(struct platform_device *pdev)
{
struct mvebu_gpio_chip *mvchip;
@@ -1246,13 +1253,18 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
return -ENODEV;
}

+ err = devm_add_action_or_reset(&pdev->dev, mvebu_gpio_remove_irq_domain,
+ mvchip->domain);
+ if (err)
+ return err;
+
err = irq_alloc_domain_generic_chips(
mvchip->domain, ngpios, 2, np->name, handle_level_irq,
IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_LEVEL, 0, 0);
if (err) {
dev_err(&pdev->dev, "couldn't allocate irq chips %s (DT).\n",
mvchip->chip.label);
- goto err_domain;
+ return err;
}

/*
@@ -1292,10 +1304,6 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
}

return 0;
-
-err_domain:
- irq_domain_remove(mvchip->domain);
- return err;
}

static struct platform_driver mvebu_gpio_driver = {
--
2.39.2



2023-07-19 13:12:35

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH] gpio: mvebu: fix irq domain leak

On Wed, Jul 19, 2023 at 2:41 PM Bartosz Golaszewski <[email protected]> wrote:
>
> From: Bartosz Golaszewski <[email protected]>
>
> Uwe Kleine-König pointed out we still have one resource leak in the mvebu
> driver triggered on driver detach. Let's address it with a custom devm
> action.

One nit-pick below, in either case
Reviewed-by: Andy Shevchenko <[email protected]>

> Fixes: 812d47889a8e ("gpio/mvebu: Use irq_domain_add_linear")
> Signed-off-by: Bartosz Golaszewski <[email protected]>
> ---
> drivers/gpio/gpio-mvebu.c | 18 +++++++++++++-----
> 1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
> index a35958e7adf6..67497116ce27 100644
> --- a/drivers/gpio/gpio-mvebu.c
> +++ b/drivers/gpio/gpio-mvebu.c
> @@ -1112,6 +1112,13 @@ static int mvebu_gpio_probe_syscon(struct platform_device *pdev,
> return 0;
> }
>
> +static void mvebu_gpio_remove_irq_domain(void *data)
> +{
> + struct irq_domain *domain = data;
> +
> + irq_domain_remove(domain);

The from/to void * doesn't need an explicit casting in C. This can be
a one liner

static void mvebu_gpio_remove_irq_domain(void *domain)
{
irq_domain_remove(domain);
}

> +}
> +
> static int mvebu_gpio_probe(struct platform_device *pdev)
> {
> struct mvebu_gpio_chip *mvchip;
> @@ -1246,13 +1253,18 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
> return -ENODEV;
> }
>
> + err = devm_add_action_or_reset(&pdev->dev, mvebu_gpio_remove_irq_domain,
> + mvchip->domain);
> + if (err)
> + return err;
> +
> err = irq_alloc_domain_generic_chips(
> mvchip->domain, ngpios, 2, np->name, handle_level_irq,
> IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_LEVEL, 0, 0);
> if (err) {
> dev_err(&pdev->dev, "couldn't allocate irq chips %s (DT).\n",
> mvchip->chip.label);
> - goto err_domain;
> + return err;
> }
>
> /*
> @@ -1292,10 +1304,6 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
> }
>
> return 0;
> -
> -err_domain:
> - irq_domain_remove(mvchip->domain);
> - return err;
> }


--
With Best Regards,
Andy Shevchenko

2023-07-19 13:56:08

by Uwe Kleine-König

[permalink] [raw]
Subject: Re: [PATCH] gpio: mvebu: fix irq domain leak

On Wed, Jul 19, 2023 at 04:02:39PM +0300, Andy Shevchenko wrote:
> On Wed, Jul 19, 2023 at 2:41 PM Bartosz Golaszewski <[email protected]> wrote:
> >
> > From: Bartosz Golaszewski <[email protected]>
> >
> > Uwe Kleine-König pointed out we still have one resource leak in the mvebu
> > driver triggered on driver detach. Let's address it with a custom devm
> > action.
>
> One nit-pick below, in either case
> Reviewed-by: Andy Shevchenko <[email protected]>
>
> > Fixes: 812d47889a8e ("gpio/mvebu: Use irq_domain_add_linear")
> > Signed-off-by: Bartosz Golaszewski <[email protected]>
> > ---
> > drivers/gpio/gpio-mvebu.c | 18 +++++++++++++-----
> > 1 file changed, 13 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
> > index a35958e7adf6..67497116ce27 100644
> > --- a/drivers/gpio/gpio-mvebu.c
> > +++ b/drivers/gpio/gpio-mvebu.c
> > @@ -1112,6 +1112,13 @@ static int mvebu_gpio_probe_syscon(struct platform_device *pdev,
> > return 0;
> > }
> >
> > +static void mvebu_gpio_remove_irq_domain(void *data)
> > +{
> > + struct irq_domain *domain = data;
> > +
> > + irq_domain_remove(domain);
>
> The from/to void * doesn't need an explicit casting in C. This can be
> a one liner
>
> static void mvebu_gpio_remove_irq_domain(void *domain)
> {
> irq_domain_remove(domain);
> }

I slightly prefer Bartosz's version, but wouldn't get sleepless nights
from that one.

Reviewed-by: Uwe Kleine-König <[email protected]>

for whatever variant you pick.

Best regards and thanks for acting on my report,
Uwe

--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |


Attachments:
(No filename) (1.81 kB)
signature.asc (499.00 B)
Download all attachments

2023-07-19 13:57:39

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH] gpio: mvebu: fix irq domain leak

On Wed, Jul 19, 2023 at 3:03 PM Andy Shevchenko
<[email protected]> wrote:
>
> On Wed, Jul 19, 2023 at 2:41 PM Bartosz Golaszewski <[email protected]> wrote:
> >
> > From: Bartosz Golaszewski <[email protected]>
> >
> > Uwe Kleine-König pointed out we still have one resource leak in the mvebu
> > driver triggered on driver detach. Let's address it with a custom devm
> > action.
>
> One nit-pick below, in either case
> Reviewed-by: Andy Shevchenko <[email protected]>
>
> > Fixes: 812d47889a8e ("gpio/mvebu: Use irq_domain_add_linear")
> > Signed-off-by: Bartosz Golaszewski <[email protected]>
> > ---
> > drivers/gpio/gpio-mvebu.c | 18 +++++++++++++-----
> > 1 file changed, 13 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
> > index a35958e7adf6..67497116ce27 100644
> > --- a/drivers/gpio/gpio-mvebu.c
> > +++ b/drivers/gpio/gpio-mvebu.c
> > @@ -1112,6 +1112,13 @@ static int mvebu_gpio_probe_syscon(struct platform_device *pdev,
> > return 0;
> > }
> >
> > +static void mvebu_gpio_remove_irq_domain(void *data)
> > +{
> > + struct irq_domain *domain = data;
> > +
> > + irq_domain_remove(domain);
>
> The from/to void * doesn't need an explicit casting in C. This can be
> a one liner
>

I know but I prioritise readability over brevity. I prefer this version.

Bart

> static void mvebu_gpio_remove_irq_domain(void *domain)
> {
> irq_domain_remove(domain);
> }
>
> > +}
> > +
> > static int mvebu_gpio_probe(struct platform_device *pdev)
> > {
> > struct mvebu_gpio_chip *mvchip;
> > @@ -1246,13 +1253,18 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
> > return -ENODEV;
> > }
> >
> > + err = devm_add_action_or_reset(&pdev->dev, mvebu_gpio_remove_irq_domain,
> > + mvchip->domain);
> > + if (err)
> > + return err;
> > +
> > err = irq_alloc_domain_generic_chips(
> > mvchip->domain, ngpios, 2, np->name, handle_level_irq,
> > IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_LEVEL, 0, 0);
> > if (err) {
> > dev_err(&pdev->dev, "couldn't allocate irq chips %s (DT).\n",
> > mvchip->chip.label);
> > - goto err_domain;
> > + return err;
> > }
> >
> > /*
> > @@ -1292,10 +1304,6 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
> > }
> >
> > return 0;
> > -
> > -err_domain:
> > - irq_domain_remove(mvchip->domain);
> > - return err;
> > }
>
>
> --
> With Best Regards,
> Andy Shevchenko