gpiolib: Don't allow drivers to specify a base with DT
PATCH 1/1 gpiolib: Don't allow drivers to specify a base with DT
From: Mark Brown <[email protected]>
DT based systems should have no reason to use fixed GPIO numbers but some drivers that work on both DT and non-DT platforms specify them anyway. In order to improve robustness in cases where drivers use gpio_is_valid() to check for a valid GPIO on data initialized to zero as a default and avoid bugs due to assuptions about fixed numbers creeping in ignore any specified base when DT is in use.
--- drivers/gpio/gpiolib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib.c +1 -1
@@ -234,7 +234,7 @@ int gpiochip_add(struct gpio_chip *chip)spin_lock_irqsave (&gpio_lock, flags); -if (base <0 ) { +if (base <0 ||of_have_populated_dt ()) { base =gpiochip_find_base (chip->ngpio);if (base <0 ) { status = base;
Signature · 1 line
2.0.1
Quoted 8 lines · Mark Brown
From: Mark Brown <[email protected]>
DT based systems should have no reason to use fixed GPIO numbers but some drivers that work on both DT and non-DT platforms specify them anyway. In order to improve robustness in cases where drivers use
gpio_is_valid()to check for a valid GPIO on data initialized to zero as a default and avoid bugs due to assuptions about fixed numbers creeping in ignore any specified base when DT is in use.
I agree that DT users should not use the base number at all - but the fact is some of them are doing it. Aren't we going to break some user-space users that will expect to find a GPIO under a given number?
Also, how is this going to help with gpio_is_valid() against zero-initialized data?
Quoted 22 lines
Signed-off-by Mark Brown <[email protected]>--- drivers/gpio/gpiolib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpio/gpiolib.c +1
-2@@ -234,7 +234,7 @@ int gpiochip_add(struct gpio_chip *chip)spin_lock_irqsave (&gpio_lock, flags); -if (base <0 ) { +if (base <0 ||of_have_populated_dt ()) { base =gpiochip_find_base (chip->ngpio);if (base <0 ) { status = base; --2.0.1
Quoted 8 lines · Mark Brown
From: Mark Brown <[email protected]>
DT based systems should have no reason to use fixed GPIO numbers but some drivers that work on both DT and non-DT platforms specify them anyway. In order to improve robustness in cases where drivers use
gpio_is_valid()to check for a valid GPIO on data initialized to zero as a default and avoid bugs due to assuptions about fixed numbers creeping in ignore any specified base when DT is in use.
Hm in principle you are right...
drivers/gpio/gpiolib.c int gpiochip_add(struct gpio_chip *chip) · line 238
Quoted 3 lines
drivers/gpio/gpiolib.c +1
-1-if (base <0 ) { +if (base <0 ||of_have_populated_dt ()) { base =gpiochip_find_base (chip->ngpio);
But here I worry about breaking in-transition systems, e.g. defining part of the peripherals through DT but adding a GPIO device with AUXDATA, setting up base that way.
Not that it should stay that way for sure, but it does need some consideration...
Yours,
Linus Walleij
Quoted 6 lines · Linus Walleij
drivers/gpio/gpiolib.c int gpiochip_add(struct gpio_chip *chip) · line 238
Quoted 3 lines · Mark Brown
drivers/gpio/gpiolib.c +1
-1-if (base <0 ) { +if (base <0 ||of_have_populated_dt ()) { base =gpiochip_find_base (chip->ngpio);
Quoted 6 lines
But here I worry about breaking in-transition systems, e.g. defining part of the peripherals through DT but adding a GPIO device with AUXDATA, setting up base that way.
Not that it should stay that way for sure, but it does need some consideration...
Could we add a flag that the boards can use to override this behaviour?
Quoted 9 lines · Alexandre Courbot
Quoted 6 lines · Mark Brown
DT based systems should have no reason to use fixed GPIO numbers but some drivers that work on both DT and non-DT platforms specify them anyway. In order to improve robustness in cases where drivers use
gpio_is_valid()to check for a valid GPIO on data initialized to zero as a default and avoid bugs due to assuptions about fixed numbers creeping in ignore any specified base when DT is in use.
Quoted 3 lines
I agree that DT users should not use the base number at all - but the fact is some of them are doing it. Aren't we going to break some user-space users that will expect to find a GPIO under a given number?
Is this actually a realistic thing that people do with mainline - I'm not convinced that it's going to be robust in general (a lot of DT conversions will have broken things for entire architectures) and hard coded numbers aren't the sort of things that make it into distros.
Quoted 2 lines
Also, how is this going to help with
gpio_is_valid()against zero-initialized data?
I should have said check for zero instead, sorry - though making 0 not be a valid GPIO would help overall.