linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: wcove: remove platform_set_drvdata() + cleanup probe
@ 2021-07-07 13:52 Alexandru Ardelean
  2021-07-07 14:08 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandru Ardelean @ 2021-07-07 13:52 UTC (permalink / raw)
  To: linux-gpio, linux-kernel
  Cc: bgolaszewski, linus.walleij, sathyanarayanan.kuppuswamy, andy,
	Alexandru Ardelean

The platform_set_drvdata() call is only useful if we need to retrieve back
the private information.
Since the driver doesn't do that, it's not useful to have it.

This change also changes the probe order a bit, moving the
devm_gpiochip_add_data() as the last call. This means that when the
gpiochip is registered [and available to consumers], it should be
initialized.

It's still possible that the devm_gpiochip_add_data() call could fail,
leaving the chip in a partially initialized state, but that was possible
even before this change; it was just some other partially initialized
state.

Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
---
 drivers/gpio/gpio-wcove.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/gpio/gpio-wcove.c b/drivers/gpio/gpio-wcove.c
index a19eeef6cf1e..2109610f5dad 100644
--- a/drivers/gpio/gpio-wcove.c
+++ b/drivers/gpio/gpio-wcove.c
@@ -428,8 +428,6 @@ static int wcove_gpio_probe(struct platform_device *pdev)
 
 	wg->regmap_irq_chip = pmic->irq_chip_data;
 
-	platform_set_drvdata(pdev, wg);
-
 	mutex_init(&wg->buslock);
 	wg->chip.label = KBUILD_MODNAME;
 	wg->chip.direction_input = wcove_gpio_dir_in;
@@ -469,12 +467,6 @@ static int wcove_gpio_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	ret = devm_gpiochip_add_data(dev, &wg->chip, wg);
-	if (ret) {
-		dev_err(dev, "Failed to add gpiochip: %d\n", ret);
-		return ret;
-	}
-
 	/* Enable GPIO0 interrupts */
 	ret = regmap_clear_bits(wg->regmap, IRQ_MASK_BASE + 0, GPIO_IRQ0_MASK);
 	if (ret)
@@ -485,7 +477,7 @@ static int wcove_gpio_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	return 0;
+	return devm_gpiochip_add_data(dev, &wg->chip, wg);
 }
 
 /*
-- 
2.31.1


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

* Re: [PATCH] gpio: wcove: remove platform_set_drvdata() + cleanup probe
  2021-07-07 13:52 [PATCH] gpio: wcove: remove platform_set_drvdata() + cleanup probe Alexandru Ardelean
@ 2021-07-07 14:08 ` Andy Shevchenko
  2021-07-08  7:03   ` Alexandru Ardelean
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2021-07-07 14:08 UTC (permalink / raw)
  To: Alexandru Ardelean
  Cc: linux-gpio, linux-kernel, bgolaszewski, linus.walleij,
	sathyanarayanan.kuppuswamy, andy

On Wed, Jul 07, 2021 at 04:52:26PM +0300, Alexandru Ardelean wrote:
> The platform_set_drvdata() call is only useful if we need to retrieve back
> the private information.
> Since the driver doesn't do that, it's not useful to have it.

This is fine.

> This change also changes the probe order a bit, moving the
> devm_gpiochip_add_data() as the last call. This means that when the
> gpiochip is registered [and available to consumers], it should be
> initialized.
> 
> It's still possible that the devm_gpiochip_add_data() call could fail,
> leaving the chip in a partially initialized state, but that was possible
> even before this change; it was just some other partially initialized
> state.

...

>  	/* Enable GPIO0 interrupts */

^^^^^

> +	return devm_gpiochip_add_data(dev, &wg->chip, wg);

This is dangerous change. How did you test it?

The handler now can be called before chip and actual handling code is
registered. It means at least two possible (bad) scenarios:
 1) the handler may dereference dangling or NULL pointer;
 2) the IRQ may be level interrupt and we may got 100000 IRQs and
    IRQ core will disable it leaving device completely unfunctional.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH] gpio: wcove: remove platform_set_drvdata() + cleanup probe
  2021-07-07 14:08 ` Andy Shevchenko
@ 2021-07-08  7:03   ` Alexandru Ardelean
  0 siblings, 0 replies; 3+ messages in thread
From: Alexandru Ardelean @ 2021-07-08  7:03 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: linux-gpio, Linux Kernel Mailing List, Bartosz Golaszewski,
	Linus Walleij, sathyanarayanan.kuppuswamy, andy

On Wed, 7 Jul 2021 at 17:09, Andy Shevchenko
<andriy.shevchenko@intel.com> wrote:
>
> On Wed, Jul 07, 2021 at 04:52:26PM +0300, Alexandru Ardelean wrote:
> > The platform_set_drvdata() call is only useful if we need to retrieve back
> > the private information.
> > Since the driver doesn't do that, it's not useful to have it.
>
> This is fine.
>
> > This change also changes the probe order a bit, moving the
> > devm_gpiochip_add_data() as the last call. This means that when the
> > gpiochip is registered [and available to consumers], it should be
> > initialized.
> >
> > It's still possible that the devm_gpiochip_add_data() call could fail,
> > leaving the chip in a partially initialized state, but that was possible
> > even before this change; it was just some other partially initialized
> > state.
>
> ...
>
> >       /* Enable GPIO0 interrupts */
>
> ^^^^^
>
> > +     return devm_gpiochip_add_data(dev, &wg->chip, wg);
>
> This is dangerous change. How did you test it?
>
> The handler now can be called before chip and actual handling code is
> registered. It means at least two possible (bad) scenarios:
>  1) the handler may dereference dangling or NULL pointer;
>  2) the IRQ may be level interrupt and we may got 100000 IRQs and
>     IRQ core will disable it leaving device completely unfunctional.


Makes sense.
Let's drop this :)


>
> --
> With Best Regards,
> Andy Shevchenko
>
>

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

end of thread, other threads:[~2021-07-08  7:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-07 13:52 [PATCH] gpio: wcove: remove platform_set_drvdata() + cleanup probe Alexandru Ardelean
2021-07-07 14:08 ` Andy Shevchenko
2021-07-08  7:03   ` Alexandru Ardelean

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