linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] gpiolib: fix allocation of mixed dynamic/static GPIOs
@ 2023-04-28 19:45 Andreas Kemnade
  2023-04-29  6:23 ` Christophe Leroy
  2023-04-29 11:10 ` Andy Shevchenko
  0 siblings, 2 replies; 3+ messages in thread
From: Andreas Kemnade @ 2023-04-28 19:45 UTC (permalink / raw)
  To: linus.walleij, brgl, christophe.leroy, andy.shevchenko,
	linux-gpio, linux-kernel, Tony Lindgren, Aaro Koskinen,
	linux-omap
  Cc: Andreas Kemnade

If static allocation and dynamic allocation GPIOs are present,
dynamic allocation pollutes the numberspace for static allocation,
causing static allocation to fail.
Enfore dynamic allocation above GPIO_DYNAMIC_BASE.

Seen on a GTA04 when omap-gpio (static) and twl-gpio (dynamic)
raced:
[some successful registrations of omap_gpio instances]
[    2.553833] twl4030_gpio twl4030-gpio: gpio (irq 145) chaining IRQs 161..178
[    2.561401] gpiochip_find_base: found new base at 160
[    2.564392] gpio gpiochip5: (twl4030): added GPIO chardev (254:5)
[    2.564544] gpio gpiochip5: registered GPIOs 160 to 177 on twl4030
[...]
[    2.692169] omap-gpmc 6e000000.gpmc: GPMC revision 5.0
[    2.697357] gpmc_mem_init: disabling cs 0 mapped at 0x0-0x1000000
[    2.703643] gpiochip_find_base: found new base at 178
[    2.704376] gpio gpiochip6: (omap-gpmc): added GPIO chardev (254:6)
[    2.704589] gpio gpiochip6: registered GPIOs 178 to 181 on omap-gpmc
[...]
[    2.840393] gpio gpiochip7: Static allocation of GPIO base is deprecated, use dynamic allocation.
[    2.849365] gpio gpiochip7: (gpio-160-191): GPIO integer space overlap, cannot add chip
[    2.857513] gpiochip_add_data_with_key: GPIOs 160..191 (gpio-160-191) failed to register, -16
[    2.866149] omap_gpio 48310000.gpio: error -EBUSY: Could not register gpio chip

On that device it is fixed invasively by
commit 92bf78b33b0b4 ("gpio: omap: use dynamic allocation of base")
but lets also fix that for devices where there is still
a mixture of static and dynamic allocation.

Fixes: 7b61212f2a07 ("gpiolib: Get rid of ARCH_NR_GPIOS")
Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
---
Changes in V2:
   handle also the case of overlapping static allocation
   across DYNAMIC_BASE

 drivers/gpio/gpiolib.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 19bd23044b017..4472214fcd43a 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -193,6 +193,8 @@ static int gpiochip_find_base(int ngpio)
 			break;
 		/* nope, check the space right after the chip */
 		base = gdev->base + gdev->ngpio;
+		if (base < GPIO_DYNAMIC_BASE)
+			base = GPIO_DYNAMIC_BASE;
 	}
 
 	if (gpio_is_valid(base)) {
-- 
2.39.2


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

* Re: [PATCH v2] gpiolib: fix allocation of mixed dynamic/static GPIOs
  2023-04-28 19:45 [PATCH v2] gpiolib: fix allocation of mixed dynamic/static GPIOs Andreas Kemnade
@ 2023-04-29  6:23 ` Christophe Leroy
  2023-04-29 11:10 ` Andy Shevchenko
  1 sibling, 0 replies; 3+ messages in thread
From: Christophe Leroy @ 2023-04-29  6:23 UTC (permalink / raw)
  To: Andreas Kemnade, linus.walleij, brgl, andy.shevchenko,
	linux-gpio, linux-kernel, Tony Lindgren, Aaro Koskinen,
	linux-omap



Le 28/04/2023 à 21:45, Andreas Kemnade a écrit :
> If static allocation and dynamic allocation GPIOs are present,
> dynamic allocation pollutes the numberspace for static allocation,
> causing static allocation to fail.
> Enfore dynamic allocation above GPIO_DYNAMIC_BASE.
> 
> Seen on a GTA04 when omap-gpio (static) and twl-gpio (dynamic)
> raced:
> [some successful registrations of omap_gpio instances]
> [    2.553833] twl4030_gpio twl4030-gpio: gpio (irq 145) chaining IRQs 161..178
> [    2.561401] gpiochip_find_base: found new base at 160
> [    2.564392] gpio gpiochip5: (twl4030): added GPIO chardev (254:5)
> [    2.564544] gpio gpiochip5: registered GPIOs 160 to 177 on twl4030
> [...]
> [    2.692169] omap-gpmc 6e000000.gpmc: GPMC revision 5.0
> [    2.697357] gpmc_mem_init: disabling cs 0 mapped at 0x0-0x1000000
> [    2.703643] gpiochip_find_base: found new base at 178
> [    2.704376] gpio gpiochip6: (omap-gpmc): added GPIO chardev (254:6)
> [    2.704589] gpio gpiochip6: registered GPIOs 178 to 181 on omap-gpmc
> [...]
> [    2.840393] gpio gpiochip7: Static allocation of GPIO base is deprecated, use dynamic allocation.
> [    2.849365] gpio gpiochip7: (gpio-160-191): GPIO integer space overlap, cannot add chip
> [    2.857513] gpiochip_add_data_with_key: GPIOs 160..191 (gpio-160-191) failed to register, -16
> [    2.866149] omap_gpio 48310000.gpio: error -EBUSY: Could not register gpio chip
> 
> On that device it is fixed invasively by
> commit 92bf78b33b0b4 ("gpio: omap: use dynamic allocation of base")
> but lets also fix that for devices where there is still
> a mixture of static and dynamic allocation.
> 
> Fixes: 7b61212f2a07 ("gpiolib: Get rid of ARCH_NR_GPIOS")
> Signed-off-by: Andreas Kemnade <andreas@kemnade.info>

Reviewed-by: <christophe.leroy@csgroup.eu>

> ---
> Changes in V2:
>     handle also the case of overlapping static allocation
>     across DYNAMIC_BASE
> 
>   drivers/gpio/gpiolib.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 19bd23044b017..4472214fcd43a 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -193,6 +193,8 @@ static int gpiochip_find_base(int ngpio)
>   			break;
>   		/* nope, check the space right after the chip */
>   		base = gdev->base + gdev->ngpio;
> +		if (base < GPIO_DYNAMIC_BASE)
> +			base = GPIO_DYNAMIC_BASE;
>   	}
>   
>   	if (gpio_is_valid(base)) {

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

* Re: [PATCH v2] gpiolib: fix allocation of mixed dynamic/static GPIOs
  2023-04-28 19:45 [PATCH v2] gpiolib: fix allocation of mixed dynamic/static GPIOs Andreas Kemnade
  2023-04-29  6:23 ` Christophe Leroy
@ 2023-04-29 11:10 ` Andy Shevchenko
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2023-04-29 11:10 UTC (permalink / raw)
  To: Andreas Kemnade
  Cc: linus.walleij, brgl, christophe.leroy, linux-gpio, linux-kernel,
	Tony Lindgren, Aaro Koskinen, linux-omap

On Fri, Apr 28, 2023 at 10:45 PM Andreas Kemnade <andreas@kemnade.info> wrote:
>
> If static allocation and dynamic allocation GPIOs are present,
> dynamic allocation pollutes the numberspace for static allocation,
> causing static allocation to fail.
> Enfore dynamic allocation above GPIO_DYNAMIC_BASE.

Enforce

> Seen on a GTA04 when omap-gpio (static) and twl-gpio (dynamic)
> raced:
> [some successful registrations of omap_gpio instances]
> [    2.553833] twl4030_gpio twl4030-gpio: gpio (irq 145) chaining IRQs 161..178
> [    2.561401] gpiochip_find_base: found new base at 160
> [    2.564392] gpio gpiochip5: (twl4030): added GPIO chardev (254:5)
> [    2.564544] gpio gpiochip5: registered GPIOs 160 to 177 on twl4030
> [...]
> [    2.692169] omap-gpmc 6e000000.gpmc: GPMC revision 5.0
> [    2.697357] gpmc_mem_init: disabling cs 0 mapped at 0x0-0x1000000
> [    2.703643] gpiochip_find_base: found new base at 178
> [    2.704376] gpio gpiochip6: (omap-gpmc): added GPIO chardev (254:6)
> [    2.704589] gpio gpiochip6: registered GPIOs 178 to 181 on omap-gpmc
> [...]
> [    2.840393] gpio gpiochip7: Static allocation of GPIO base is deprecated, use dynamic allocation.
> [    2.849365] gpio gpiochip7: (gpio-160-191): GPIO integer space overlap, cannot add chip
> [    2.857513] gpiochip_add_data_with_key: GPIOs 160..191 (gpio-160-191) failed to register, -16
> [    2.866149] omap_gpio 48310000.gpio: error -EBUSY: Could not register gpio chip
>
> On that device it is fixed invasively by
> commit 92bf78b33b0b4 ("gpio: omap: use dynamic allocation of base")
> but lets also fix that for devices where there is still

let's

> a mixture of static and dynamic allocation.

It might be that it can be optimized, but OK for now. Thanks for fixing it.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

> Fixes: 7b61212f2a07 ("gpiolib: Get rid of ARCH_NR_GPIOS")
> Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
> ---
> Changes in V2:
>    handle also the case of overlapping static allocation
>    across DYNAMIC_BASE
>
>  drivers/gpio/gpiolib.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 19bd23044b017..4472214fcd43a 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -193,6 +193,8 @@ static int gpiochip_find_base(int ngpio)
>                         break;
>                 /* nope, check the space right after the chip */
>                 base = gdev->base + gdev->ngpio;
> +               if (base < GPIO_DYNAMIC_BASE)
> +                       base = GPIO_DYNAMIC_BASE;
>         }
>
>         if (gpio_is_valid(base)) {
> --
> 2.39.2
>


-- 
With Best Regards,
Andy Shevchenko

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

end of thread, other threads:[~2023-04-29 11:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-28 19:45 [PATCH v2] gpiolib: fix allocation of mixed dynamic/static GPIOs Andreas Kemnade
2023-04-29  6:23 ` Christophe Leroy
2023-04-29 11:10 ` Andy Shevchenko

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