tty/serial: sh-sci: remove uneeded IS_ERR_OR_NULL calls
Subsystems (2)
PATCH 4/4 tty/serial: sh-sci: remove uneeded IS_ERR_OR_NULL calls
Since commit 1d267ea6539f ("serial: mctrl-gpio: simplify init routine"), the mctrl_gpio_to_gpiod() function can't return an error anymore. So, just testing for a NULL pointer is ok.
--- drivers/tty/serial/sh-sci.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/tty/serial/sh-sci.c +5 -7
@@ -1934,12 +1934,12 @@ static unsigned int sci_get_mctrl(struct uart_port *port)if (s->autorts) {if (sci_get_cts (port)) mctrl |=TIOCM_CTS ; - }else if (IS_ERR_OR_NULL (mctrl_gpio_to_gpiod (gpios,UART_GPIO_CTS ))) { + }else if (!mctrl_gpio_to_gpiod (gpios,UART_GPIO_CTS )) { mctrl |=TIOCM_CTS ; } -if (IS_ERR_OR_NULL (mctrl_gpio_to_gpiod (gpios,UART_GPIO_DSR ))) +if (!mctrl_gpio_to_gpiod (gpios,UART_GPIO_DSR )) mctrl |=TIOCM_DSR ; -if (IS_ERR_OR_NULL (mctrl_gpio_to_gpiod (gpios,UART_GPIO_DCD ))) +if (!mctrl_gpio_to_gpiod (gpios,UART_GPIO_DCD )) mctrl |=TIOCM_CAR ;return mctrl;
@@ -3072,10 +3072,8 @@ static int sci_probe_single(struct platform_device *dev,return PTR_ERR (sciport->gpios);if (sciport->has_rtscts) { -if (!IS_ERR_OR_NULL (mctrl_gpio_to_gpiod (sciport->gpios, -UART_GPIO_CTS )) || - !IS_ERR_OR_NULL (mctrl_gpio_to_gpiod (sciport->gpios, -UART_GPIO_RTS ))) { +if (mctrl_gpio_to_gpiod (sciport->gpios,UART_GPIO_CTS ) || +mctrl_gpio_to_gpiod (sciport->gpios,UART_GPIO_RTS )) {dev_err (&dev->dev,"Conflicting RTS/CTS config\n" );return -EINVAL ; }
Hi Richard,
Quoted 3 lines · Richard Genoud
Since commit
1d267ea6539f("serial: mctrl-gpio: simplify init routine"), themctrl_gpio_to_gpiod()function can't return an error anymore. So, just testing for a NULL pointer is ok.
If CONFIG_GPIOLIB=n, mctrl_gpio_to_gpiod() always returns ERR_PTR(-ENOSYS). That case should be handled correctly, too.
Perhaps mctrl_gpio_to_gpiod() should always return NULL if !CONFIG_GPIOLIB?
This may apply to the other 2 patches, too:
[PATCH 2/4] tty/serial: atmel: remove uneeded IS_ERR_OR_NULL calls [PATCH 3/4] tty/serial: mxs-auart: remove uneeded IS_ERR_OR_NULL calls
Quoted 28 lines
Signed-off-by Richard Genoud <[email protected]>--- drivers/tty/serial/sh-sci.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)drivers/tty/serial/sh-sci.c +3
-3@@ -1934,12 +1934,12 @@ static unsigned int sci_get_mctrl(struct uart_port *port)if (s->autorts) {if (sci_get_cts (port)) mctrl |=TIOCM_CTS ; - }else if (IS_ERR_OR_NULL (mctrl_gpio_to_gpiod (gpios,UART_GPIO_CTS ))) { + }else if (!mctrl_gpio_to_gpiod (gpios,UART_GPIO_CTS )) { mctrl |=TIOCM_CTS ; } -if (IS_ERR_OR_NULL (mctrl_gpio_to_gpiod (gpios,UART_GPIO_DSR ))) +if (!mctrl_gpio_to_gpiod (gpios,UART_GPIO_DSR )) mctrl |=TIOCM_DSR ; -if (IS_ERR_OR_NULL (mctrl_gpio_to_gpiod (gpios,UART_GPIO_DCD ))) +if (!mctrl_gpio_to_gpiod (gpios,UART_GPIO_DCD )) mctrl |=TIOCM_CAR ;return mctrl;@@ -3072,10 +3072,8 @@ static int sci_probe_single(struct platform_device *dev,return PTR_ERR (sciport->gpios);
drivers/tty/serial/sh-sci.c static int sci_probe_single(struct platform_device *dev, · line 3079
Quoted 10 lines
drivers/tty/serial/sh-sci.c +2
-4if (sciport->has_rtscts) { -if (!IS_ERR_OR_NULL (mctrl_gpio_to_gpiod (sciport->gpios, -UART_GPIO_CTS )) || - !IS_ERR_OR_NULL (mctrl_gpio_to_gpiod (sciport->gpios, -UART_GPIO_RTS ))) { +if (mctrl_gpio_to_gpiod (sciport->gpios,UART_GPIO_CTS ) || +mctrl_gpio_to_gpiod (sciport->gpios,UART_GPIO_RTS )) {dev_err (&dev->dev,"Conflicting RTS/CTS config\n" );return -EINVAL ; }
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Quoted 9 lines · Geert Uytterhoeven
Hi Richard,
Quoted 3 lines · Richard Genoud
Since commit
1d267ea6539f("serial: mctrl-gpio: simplify init routine"), themctrl_gpio_to_gpiod()function can't return an error anymore. So, just testing for a NULL pointer is ok.If
CONFIG_GPIOLIB=n,mctrl_gpio_to_gpiod()always returnsERR_PTR(-ENOSYS). That case should be handled correctly, too.
The correct change to handle this is:
drivers/tty/serial/sh-sci.c +1 -1
@@ -3022,7 +3022,7 @@ static int sci_probe_single(struct platform_device *dev,return ret; sciport->gpios =mctrl_gpio_init (&sciport->port,0 ); -if (IS_ERR (sciport->gpios) &&PTR_ERR (sciport->gpios) != -ENOSYS ) +if (IS_ERR (sciport->gpios))return PTR_ERR (sciport->gpios);if (p->capabilities & SCIx_HAVE_RTSCTS) {
Then mctrl_gpio_to_gpiod isn't called. I don't have a machine to test this, but I think currently this makes the machine barf to continue here because with sciport->gpios = ERR_PTR(-ENOSYS) calling
mctrl_gpio_to_gpiod(sciport->gpios, ...)
is a bad idea.
Quoted 1 line
Perhaps
mctrl_gpio_to_gpiod()should always return NULL if !CONFIG_GPIOLIB?
No, mctrl_gpio_to_gpiod is right. You are only supposed to call it if mctrl_gpio_init succeeded.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
Hi Uwe,
Quoted 16 lines · Uwe Kleine-K?nig
Quoted 7 lines · Geert Uytterhoeven
Quoted 3 lines · Richard Genoud
Since commit
1d267ea6539f("serial: mctrl-gpio: simplify init routine"), themctrl_gpio_to_gpiod()function can't return an error anymore. So, just testing for a NULL pointer is ok.If
CONFIG_GPIOLIB=n,mctrl_gpio_to_gpiod()always returnsERR_PTR(-ENOSYS). That case should be handled correctly, too.The correct change to handle this is:
drivers/tty/serial/sh-sci.c +0
-0
drivers/tty/serial/sh-sci.c static int sci_probe_single(struct platform_device *dev, · line 3026
Quoted 6 lines
drivers/tty/serial/sh-sci.c +1
-1@@ -3022,7 +3022,7 @@ static int sci_probe_single(struct platform_device *dev,return ret; sciport->gpios =mctrl_gpio_init (&sciport->port,0 ); -if (IS_ERR (sciport->gpios) &&PTR_ERR (sciport->gpios) != -ENOSYS ) +if (IS_ERR (sciport->gpios))return PTR_ERR (sciport->gpios);
Now the sh-sci driver fails to probe on legacy platforms where GPIOLIB=n. The check for -ENOSYS made it succeed before.
Quoted 7 lines
Then
mctrl_gpio_to_gpiodisn't called. I don't have a machine to test this, but I think currently this makes the machine barf to continue here because withsciport->gpios=ERR_PTR(-ENOSYS)callingmctrl_gpio_to_gpiod(sciport->gpios, ...)is a bad idea.
If sciport->gpios == ERR_PTR(-ENOSYS), CONFIG_GPIOLIB is not enabled, the feature is not available, and mctrl_gpio_to_gpiod() will not dereference the error
pointer.
Quoted 4 lines
Quoted 1 line
Perhaps
mctrl_gpio_to_gpiod()should always return NULL if !CONFIG_GPIOLIB?No,
mctrl_gpio_to_gpiodis right. You are only supposed to call it ifmctrl_gpio_initsucceeded.
Then I have to add checks for sciport->gpios == ERR_PTR(-ENOSYS)...
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Hello Geert,
Quoted 7 lines · Geert Uytterhoeven
Quoted 7 lines
drivers/tty/serial/sh-sci.c +0
-0@@ -3022,7 +3022,7 @@ static int sci_probe_single(struct platform_device *dev,return ret;
Quoted 7 lines
drivers/tty/serial/sh-sci.c static int sci_probe_single(struct platform_device *dev, · line 3026
Quoted 4 lines
drivers/tty/serial/sh-sci.c +1
-1sciport->gpios =mctrl_gpio_init (&sciport->port,0 ); -if (IS_ERR (sciport->gpios) &&PTR_ERR (sciport->gpios) != -ENOSYS ) +if (IS_ERR (sciport->gpios))return PTR_ERR (sciport->gpios);Now the sh-sci driver fails to probe on legacy platforms where GPIOLIB=n. The check for
-ENOSYSmade it succeed before.
That's right, intended and the only option that's save (for some definition of save; the obvious downside is that there is no /dev/tty$whatever for you).
Ignoring -ENOSYS is only ok if your device doesn't have a cts-gpio. If it has, ignoring -ENOSYS hides bugs because the driver sends data while it shouldn't or cannot signal the other side that it should stop (or start) a transmission.
So the options are:
- enable GPIOLIB (maybe enforce that by letting the driver select it)
- introduce a CONFIG_HALFGPIOLIB that makes gpiod_get_optional and mctrl_gpio_init return only then -ENOSYS if there is a gpio specified and NULL otherwise.
Quoted 4 lines
Quoted 4 lines
Then
mctrl_gpio_to_gpiodisn't called. I don't have a machine to test this, but I think currently this makes the machine barf to continue here because withsciport->gpios=ERR_PTR(-ENOSYS)calling
Quoted 8 lines
Quoted 3 lines
mctrl_gpio_to_gpiod(sciport->gpios, ...)is a bad idea.
If
sciport->gpios==ERR_PTR(-ENOSYS),CONFIG_GPIOLIBis not enabled, the feature is not available, andmctrl_gpio_to_gpiod()will not dereference the error
pointer.
Ah, makes sense.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Perhaps
mctrl_gpio_to_gpiod()should always return NULL if !CONFIG_GPIOLIB?No,
mctrl_gpio_to_gpiodis right. You are only supposed to call it ifmctrl_gpio_initsucceeded.Then I have to add checks for
sciport->gpios==ERR_PTR(-ENOSYS)...
No, ignoring -ENOSYS is wrong.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
Hi Uwe,
Quoted 16 lines · Uwe Kleine-K?nig
Quoted 7 lines · Geert Uytterhoeven
Quoted 7 lines
drivers/tty/serial/sh-sci.c +0
-0@@ -3022,7 +3022,7 @@ static int sci_probe_single(struct platform_device *dev,return ret;Quoted 7 lines
drivers/tty/serial/sh-sci.c static int sci_probe_single(struct platform_device *dev, · line 3026
Quoted 4 lines
drivers/tty/serial/sh-sci.c +1
-1sciport->gpios =mctrl_gpio_init (&sciport->port,0 ); -if (IS_ERR (sciport->gpios) &&PTR_ERR (sciport->gpios) != -ENOSYS ) +if (IS_ERR (sciport->gpios))return PTR_ERR (sciport->gpios);Now the sh-sci driver fails to probe on legacy platforms where GPIOLIB=n. The check for
-ENOSYSmade it succeed before.
Quoted 3 lines
That's right, intended and the only option that's save (for some definition of save; the obvious downside is that there is no
/dev/tty$whateverfor you).
That's not just a downside, but a plain regression on legacy platforms that do not use GPIO flow control.
Quoted 4 lines
Ignoring
-ENOSYSis only ok if your device doesn't have a cts-gpio. If it has, ignoring-ENOSYShides bugs because the driver sends data while it shouldn't or cannot signal the other side that it should stop (or start) a transmission.
Mctrl_gpio supports modern platforms with GPIOLIB and DT or ACPI only. On legacy platforms, you cannot use GPIO flow control (except when using a custom implementation, which is out-of-scope here), so the issue of silently running without cts-gpio on these platforms is moot.
Quoted 21 lines
So the options are:
- enable GPIOLIB (maybe enforce that by letting the driver select it)
- introduce aCONFIG_HALFGPIOLIBthat makesgpiod_get_optionalandmctrl_gpio_initreturn only then-ENOSYSif there is a gpio specified and NULL otherwise.Quoted 4 lines
Quoted 4 lines
Then
mctrl_gpio_to_gpiodisn't called. I don't have a machine to test this, but I think currently this makes the machine barf to continue here because withsciport->gpios=ERR_PTR(-ENOSYS)callingQuoted 8 lines
Quoted 3 lines
mctrl_gpio_to_gpiod(sciport->gpios, ...)is a bad idea.
If
sciport->gpios==ERR_PTR(-ENOSYS),CONFIG_GPIOLIBis not enabled, the feature is not available, andmctrl_gpio_to_gpiod()will not dereference the error
pointer.Ah, makes sense.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Perhaps
mctrl_gpio_to_gpiod()should always return NULL if !CONFIG_GPIOLIB?No,
mctrl_gpio_to_gpiodis right. You are only supposed to call it ifmctrl_gpio_initsucceeded.Then I have to add checks for
sciport->gpios==ERR_PTR(-ENOSYS)...No, ignoring
-ENOSYSis wrong.
How else to handle this in a driver that supports both modern (DT && GPIOLIB) and legacy platforms?
sh-sci is not only used on DT-only architectures like arm, arm64, and h8300, but also on SuperH, where some platforms use GPIOLIB, others don't, and none of them use DT yet (jcore doesn't matter, as it doesn't use sh-sci).
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Hello,
Cc += linux-gpio at vger.kernel.org
Quoted 18 lines · Geert Uytterhoeven
Quoted 16 lines · Uwe Kleine-K?nig
Quoted 14 lines · Geert Uytterhoeven
drivers/tty/serial/sh-sci.c static int sci_probe_single(struct platform_device *dev, · line 3026
Quoted 11 lines
drivers/tty/serial/sh-sci.c +1
-1@@ -3022,7 +3022,7 @@ static int sci_probe_single(struct platform_device *dev,return ret; sciport->gpios =mctrl_gpio_init (&sciport->port,0 ); -if (IS_ERR (sciport->gpios) &&PTR_ERR (sciport->gpios) != -ENOSYS ) +if (IS_ERR (sciport->gpios))return PTR_ERR (sciport->gpios);Now the sh-sci driver fails to probe on legacy platforms where GPIOLIB=n. The check for
-ENOSYSmade it succeed before.
Quoted 6 lines
Quoted 3 lines
That's right, intended and the only option that's save (for some definition of save; the obvious downside is that there is no
/dev/tty$whateverfor you).That's not just a downside, but a plain regression on legacy platforms that do not use GPIO flow control.
The only sane way out is that the driver somehow finds out that no gpios are supposed to be needed. So you can pass in via platform_data that no gpios are supposed to be used if you don't want to enable GPIOLIB (or implement CONFIG_HALFGPIOLIB). But I'd say this is a quirk that should better be fixed globally. So I think we should implement HALFGPIOLIB that includes the lookup stuff and so can make gpiod_get_optional and friends return NULL if there is really no GPIO.
Quoted 6 lines
Quoted 4 lines
Ignoring
-ENOSYSis only ok if your device doesn't have a cts-gpio. If it has, ignoring-ENOSYShides bugs because the driver sends data while it shouldn't or cannot signal the other side that it should stop (or start) a transmission.
Mctrl_gpiosupports modern platforms with GPIOLIB and DT or ACPI only.
That's wrong. Even for a legacy device you can make use of GPIOs. See arch/arm/mach-tegra/board-paz00.c for a simple example.
Quoted 3 lines
On legacy platforms, you cannot use GPIO flow control (except when using a custom implementation, which is out-of-scope here), so the issue of silently running without cts-gpio on these platforms is moot.
Given that mctrl-gpio can be useful on legacy platforms, a device could silently run without cts-gpio even there.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
Hi Uwe,
Quoted 28 lines · Uwe Kleine-K?nig
Cc += linux-gpio at vger.kernel.org
Quoted 18 lines · Geert Uytterhoeven
Quoted 16 lines · Uwe Kleine-K?nig
Quoted 14 lines · Geert Uytterhoeven
drivers/tty/serial/sh-sci.c static int sci_probe_single(struct platform_device *dev, · line 3026
Quoted 11 lines
drivers/tty/serial/sh-sci.c +1
-1@@ -3022,7 +3022,7 @@ static int sci_probe_single(struct platform_device *dev,return ret; sciport->gpios =mctrl_gpio_init (&sciport->port,0 ); -if (IS_ERR (sciport->gpios) &&PTR_ERR (sciport->gpios) != -ENOSYS ) +if (IS_ERR (sciport->gpios))return PTR_ERR (sciport->gpios);Now the sh-sci driver fails to probe on legacy platforms where GPIOLIB=n. The check for
-ENOSYSmade it succeed before.Quoted 6 lines
Quoted 3 lines
That's right, intended and the only option that's save (for some definition of save; the obvious downside is that there is no
/dev/tty$whateverfor you).That's not just a downside, but a plain regression on legacy platforms that do not use GPIO flow control.
Quoted 7 lines
The only sane way out is that the driver somehow finds out that no gpios are supposed to be needed. So you can pass in via
platform_datathat no gpios are supposed to be used if you don't want to enable GPIOLIB (or implementCONFIG_HALFGPIOLIB). But I'd say this is a quirk that should better be fixed globally. So I think we should implement HALFGPIOLIB that includes the lookup stuff and so can makegpiod_get_optionaland friends return NULL if there is really no GPIO.
If CONFIG_GPIOLIB=n, no gpios are supposed to be needed.
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Ignoring
-ENOSYSis only ok if your device doesn't have a cts-gpio. If it has, ignoring-ENOSYShides bugs because the driver sends data while it shouldn't or cannot signal the other side that it should stop (or start) a transmission.
Mctrl_gpiosupports modern platforms with GPIOLIB and DT or ACPI only.That's wrong. Even for a legacy device you can make use of GPIOs. See
arch/arm/mach-tegra/board-paz00.cfor a simple example.
Sorry, forgot about gpiod_lookup_table. It's not used by any platform using the sh-sci serial driver.
Still, using gpiod_lookup_table depends on CONFIG_GPIOLIB=y.
Quoted 6 lines
Quoted 3 lines
On legacy platforms, you cannot use GPIO flow control (except when using a custom implementation, which is out-of-scope here), so the issue of silently running without cts-gpio on these platforms is moot.
Given that mctrl-gpio can be useful on legacy platforms, a device could silently run without cts-gpio even there.
On platforms were CONFIG_GPIOLIB=n, this is not true, so the issue is moot.
All serial drivers using (optional) mctrl-gpio have this in Kconfig:
select SERIAL_MCTRL_GPIO if GPIOLIB
So they will use mctrl-gpio when GPIOLIB is enabled.
If GPIOPLIB is disabled, no flow control GPIOs are expected, and the driver should not break that case.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Hello Geert,
Quoted 5 lines · Geert Uytterhoeven
Quoted 2 lines
Given that mctrl-gpio can be useful on legacy platforms, a device could silently run without cts-gpio even there.
On platforms were
CONFIG_GPIOLIB=n, this is not true, so the issue is moot.
Quoted 7 lines
All serial drivers using (optional) mctrl-gpio have this in
Kconfig:select
SERIAL_MCTRL_GPIOif GPIOLIBSo they will use mctrl-gpio when GPIOLIB is enabled.
If GPIOPLIB is disabled, no flow control GPIOs are expected, and the driver should not break that case.
So it all boils down to the question: Is GPIOLIB=n enough to assume no gpio is needed?
I'd say it is not.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
Hi Uwe,
Quoted 10 lines · Uwe Kleine-K?nig
Quoted 9 lines · Geert Uytterhoeven
Quoted 2 lines
Given that mctrl-gpio can be useful on legacy platforms, a device could silently run without cts-gpio even there.
On platforms were
CONFIG_GPIOLIB=n, this is not true, so the issue is moot.All serial drivers using (optional) mctrl-gpio have this in
Kconfig:select
SERIAL_MCTRL_GPIOif GPIOLIB
Quoted 8 lines
Quoted 3 lines
So they will use mctrl-gpio when GPIOLIB is enabled.
If GPIOPLIB is disabled, no flow control GPIOs are expected, and the driver should not break that case.So it all boils down to the question: Is GPIOLIB=n enough to assume no gpio is needed?
I'd say it is not.
How does the platform register these GPIOs when GPIOPLIB is not enabled by the platform, and gpiod_add_lookup_table() is thus not available?
Please show me an example.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Hello Geert,
Quoted 16 lines · Geert Uytterhoeven
Quoted 14 lines · Uwe Kleine-K?nig
Quoted 12 lines · Geert Uytterhoeven
Quoted 2 lines
Given that mctrl-gpio can be useful on legacy platforms, a device could silently run without cts-gpio even there.
On platforms were
CONFIG_GPIOLIB=n, this is not true, so the issue is moot.All serial drivers using (optional) mctrl-gpio have this in
Kconfig:select
SERIAL_MCTRL_GPIOif GPIOLIBSo they will use mctrl-gpio when GPIOLIB is enabled.
If GPIOPLIB is disabled, no flow control GPIOs are expected, and the driver should not break that case.
Quoted 7 lines
Quoted 4 lines
So it all boils down to the question: Is GPIOLIB=n enough to assume no gpio is needed?
I'd say it is not.
How does the platform register these GPIOs when GPIOPLIB is not enabled by the platform, and
gpiod_add_lookup_table()is thus not available?
Obviously the platformcode cannot. In this case you could argue that platformcode shouldn't register the device if a gpio is necessary. But this reasoning doesn't work for (DT=y || ACPI=y) && GPIOLIB=n.
I wouldn't want to code this in each driver (something like:
if (IS_ENABLED(GPIOLIB) || device_is_instantiated_by_dt(dev) || device_is_instantiated_by_acpi(dev)) gpios = mctrl_gpio_init(...); else gpios = NULL;
). Putting this into GPIOLIB is the right approach, and so this is another argument for HALFGPIOLIB. This would fix mctrl_gpio_init en passant.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
Hi Uwe,
Quoted 31 lines · Uwe Kleine-K?nig
Quoted 16 lines · Geert Uytterhoeven
Quoted 14 lines · Uwe Kleine-K?nig
Quoted 12 lines · Geert Uytterhoeven
Quoted 2 lines
Given that mctrl-gpio can be useful on legacy platforms, a device could silently run without cts-gpio even there.
On platforms were
CONFIG_GPIOLIB=n, this is not true, so the issue is moot.All serial drivers using (optional) mctrl-gpio have this in
Kconfig:select
SERIAL_MCTRL_GPIOif GPIOLIBSo they will use mctrl-gpio when GPIOLIB is enabled.
If GPIOPLIB is disabled, no flow control GPIOs are expected, and the driver should not break that case.Quoted 7 lines
Quoted 4 lines
So it all boils down to the question: Is GPIOLIB=n enough to assume no gpio is needed?
I'd say it is not.
How does the platform register these GPIOs when GPIOPLIB is not enabled by the platform, and
gpiod_add_lookup_table()is thus not available?Obviously the platformcode cannot. In this case you could argue that platformcode shouldn't register the device if a gpio is necessary. But this reasoning doesn't work for (DT=y || ACPI=y) && GPIOLIB=n.
I wouldn't want to code this in each driver (something like:
Quoted 8 lines
if (IS_ENABLED(GPIOLIB) || device_is_instantiated_by_dt(dev) || device_is_instantiated_by_acpi(dev)) gpios = mctrl_gpio_init(...); else gpios = NULL;). Putting this into GPIOLIB is the right approach, and so this is another argument for HALFGPIOLIB. This would fix
mctrl_gpio_initen passant.
Do we have platforms where DT=y || ACPI=y, but GPIOLIB=n? Ah, x86 ;-)
Anyway, for sh-sci.c, platforms either have DT and GPIOLIB, or they do not need mctrl-gpio.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Cc += LinusW
Quoted 38 lines · Geert Uytterhoeven
Quoted 36 lines · Uwe Kleine-K?nig
Quoted 16 lines · Geert Uytterhoeven
Quoted 14 lines · Uwe Kleine-K?nig
Quoted 12 lines · Geert Uytterhoeven
Quoted 2 lines
Given that mctrl-gpio can be useful on legacy platforms, a device could silently run without cts-gpio even there.
On platforms were
CONFIG_GPIOLIB=n, this is not true, so the issue is moot.All serial drivers using (optional) mctrl-gpio have this in
Kconfig:select
SERIAL_MCTRL_GPIOif GPIOLIBSo they will use mctrl-gpio when GPIOLIB is enabled.
If GPIOPLIB is disabled, no flow control GPIOs are expected, and the driver should not break that case.Quoted 7 lines
Quoted 4 lines
So it all boils down to the question: Is GPIOLIB=n enough to assume no gpio is needed?
I'd say it is not.
How does the platform register these GPIOs when GPIOPLIB is not enabled by the platform, and
gpiod_add_lookup_table()is thus not available?Obviously the platformcode cannot. In this case you could argue that platformcode shouldn't register the device if a gpio is necessary. But this reasoning doesn't work for (DT=y || ACPI=y) && GPIOLIB=n.
I wouldn't want to code this in each driver (something like:
if (IS_ENABLED(GPIOLIB) || device_is_instantiated_by_dt(dev) || device_is_instantiated_by_acpi(dev)) gpios = mctrl_gpio_init(...); else gpios = NULL;
Quoted 6 lines
Quoted 3 lines
). Putting this into GPIOLIB is the right approach, and so this is another argument for HALFGPIOLIB. This would fix
mctrl_gpio_initen passant.Do we have platforms where DT=y || ACPI=y, but GPIOLIB=n? Ah, x86 ;-)
Yeah, and I think rm -r arch/x86 won't be acceptable :-) I assume you can also configure some arm or powerpc systems without GPIOLIB.
Quoted 2 lines
Anyway, for
sh-sci.c, platforms either have DT and GPIOLIB, or they do not need mctrl-gpio.
So we're in agreement now that HALFGPIOLIB is the way to go? Linus, what do you think?
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
Quoted 5 lines · Uwe Kleine-K?nig
Quoted 2 lines
Anyway, for
sh-sci.c, platforms either have DT and GPIOLIB, or they do not need mctrl-gpio.So we're in agreement now that HALFGPIOLIB is the way to go? Linus, what do you think?
I'm too swamped in mail and work to figure this out right now. I guess I will get back to it...
I need more active comaintainers I guess, interested in the job? ;)
Yours,
Linus Walleij
Quoted 17 lines · Uwe Kleine-K?nig
Quoted 9 lines · Geert Uytterhoeven
On Mon, Mar 6, 2017 at 10:30 AM, Uwe Kleine-K?nig
Quoted 7 lines
I wouldn't want to code this in each driver (something like:
if (IS_ENABLED(GPIOLIB) || device_is_instantiated_by_dt(dev) || device_is_instantiated_by_acpi(dev)) gpios = mctrl_gpio_init(...); else gpios = NULL;Quoted 6 lines
Quoted 3 lines
). Putting this into GPIOLIB is the right approach, and so this is another argument for HALFGPIOLIB. This would fix
mctrl_gpio_initen passant.Do we have platforms where DT=y || ACPI=y, but GPIOLIB=n? Ah, x86 ;-)
Quoted 8 lines
Yeah, and I think rm -r
arch/x86won't be acceptable :-) I assume you can also configure some arm or powerpc systems without GPIOLIB.Quoted 2 lines
Anyway, for
sh-sci.c, platforms either have DT and GPIOLIB, or they do not need mctrl-gpio.So we're in agreement now that HALFGPIOLIB is the way to go? Linus, what do you think?
OK modem lines over GPIO.
So the problem is that GPIOLIB is needed (obviously) for mctrl_gpio_init() to work properly, and then there are some stubs in drivers/tty/serial/serial_mctrl_gpio.h
for !GPIOLIB.
And this whole discussion is all about that !GPIOLIB case really, whether DT, ACPI, SFI or board files machine data is used doesn't really matter.
We're talking about:
Quoted 1 line
git grep
mctrl_gpio_init
drivers/tty/serial/atmel_serial.c: atmel_port->gpios =mctrl_gpio_init(&atmel_port->uart, 0);drivers/tty/serial/clps711x.c: s->gpios =mctrl_gpio_init_noauto(&pdev->dev, 0);drivers/tty/serial/etraxfs-uart.c: up->gpios =mctrl_gpio_init_noauto(&pdev->dev, 0);
drivers/tty/serial/imx.c: sport->gpios = mctrl_gpio_init(&sport->port, 0); drivers/tty/serial/mxs-auart.c: s->gpios = mctrl_gpio_init_noauto(dev, 0); drivers/tty/serial/sh-sci.c: sciport->gpios =
mctrl_gpio_init(&sciport->port, 0);
Atmel, ARM, ETRAX, ARM, ARM, Super-H, all have GPIOLIB. Right now no x86, correct?
They actually all even do things like this in Kconfig:
config SERIAL_ATMEL
(...)
select SERIAL_MCTRL_GPIO if GPIOLIB
What stops us from removing all the stubs in drivers/tty/serial/serial_mctrl_gpio.h
and just make SERIAL_MCTRL_GPIO depends on GPIOLIB?
Quoted 1 line
From
2ecc70acc510784d953add707f2a5acfebe484c2Mon Sep 17 00:00:00 2001
From: Linus Walleij <[email protected]>
Date: Thu, 16 Mar 2017 16:18:21 +0100
Subject: [PATCH] stab at mctrl
--- drivers/tty/serial/Kconfig | 1 + drivers/tty/serial/serial_mctrl_gpio.h | 55 ---------------------------------- 2 files changed, 1 insertion(+), 55 deletions(-)
drivers/tty/serial/Kconfig +1 -0
@@ -1681,5 +1681,6 @@ endmenu config SERIAL_MCTRL_GPIO tristate + depends on GPIOLIB endif # TTY
(quoted diff) +0 -0
b/drivers/tty/serial/serial_mctrl_gpio.h
index fa000bcff217..ba8f8e531d56 100644
drivers/tty/serial/serial_mctrl_gpio.h +0 -36
@@ -40,8 +40,6 @@ enum mctrl_gpio_idx {*/ struct mctrl_gpios ; -#ifdef CONFIG_GPIOLIB -/* * Set state of the modem control output lines via GPIOs. */
@@ -101,57 +99,4 @@ void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios);*/ void mctrl_gpio_disable_ms (struct mctrl_gpios *gpios); -#else /* GPIOLIB */ - -static inline -void mctrl_gpio_set (struct mctrl_gpios *gpios,unsigned int mctrl) -{ -} - -static inline -unsigned int mctrl_gpio_get (struct mctrl_gpios *gpios,unsigned int *mctrl) -{ -return *mctrl; -} - -static inline unsigned int -mctrl_gpio_get_outputs (struct mctrl_gpios *gpios,unsigned int *mctrl) -{ -return *mctrl; -} - -static inline -struct gpio_desc *mctrl_gpio_to_gpiod (struct mctrl_gpios *gpios, -enum mctrl_gpio_idx gidx) -{ -return ERR_PTR (-ENOSYS ); -} - -static inline -struct mctrl_gpios *mctrl_gpio_init (struct uart_port *port,unsigned int idx) -{ -return ERR_PTR (-ENOSYS ); -} - -static inline -struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev,
unsigned int idx)
-{
- return ERR_PTR(-ENOSYS);
-}
-
-static inline
-void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios) -{
-}
-
-static inline void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios) -{
-}
-
-static inline void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios) -{
-}
-
-#endif /* GPIOLIB */
-
#endif
Signature · 5 lines
2.9.3 Yours, Linus Walleij
Quoted 58 lines · Linus Walleij
Quoted 17 lines · Uwe Kleine-K?nig
Quoted 9 lines · Geert Uytterhoeven
On Mon, Mar 6, 2017 at 10:30 AM, Uwe Kleine-K?nig
Quoted 7 lines
I wouldn't want to code this in each driver (something like:
if (IS_ENABLED(GPIOLIB) || device_is_instantiated_by_dt(dev) || device_is_instantiated_by_acpi(dev)) gpios = mctrl_gpio_init(...); else gpios = NULL;Quoted 6 lines
Quoted 3 lines
). Putting this into GPIOLIB is the right approach, and so this is another argument for HALFGPIOLIB. This would fix
mctrl_gpio_initen passant.Do we have platforms where DT=y || ACPI=y, but GPIOLIB=n? Ah, x86 ;-)
Quoted 8 lines
Yeah, and I think rm -r
arch/x86won't be acceptable :-) I assume you can also configure some arm or powerpc systems without GPIOLIB.Quoted 2 lines
Anyway, for
sh-sci.c, platforms either have DT and GPIOLIB, or they do not need mctrl-gpio.So we're in agreement now that HALFGPIOLIB is the way to go? Linus, what do you think?
OK modem lines over GPIO.
So the problem is that GPIOLIB is needed (obviously) for
mctrl_gpio_init()to work properly, and then there are some stubs indrivers/tty/serial/serial_mctrl_gpio.h
for !GPIOLIB.And this whole discussion is all about that !GPIOLIB case really, whether DT, ACPI, SFI or board files machine data is used doesn't really matter.
We're talking about:
Quoted 1 line
git grep
mctrl_gpio_init
drivers/tty/serial/atmel_serial.c:atmel_port->gpios=mctrl_gpio_init(&atmel_port->uart, 0);drivers/tty/serial/clps711x.c:s->gpios=mctrl_gpio_init_noauto(&pdev->dev, 0);drivers/tty/serial/etraxfs-uart.c:up->gpios=mctrl_gpio_init_noauto(&pdev->dev, 0);drivers/tty/serial/imx.c: sport->gpios = mctrl_gpio_init(&sport->port, 0); drivers/tty/serial/mxs-auart.c: s->gpios = mctrl_gpio_init_noauto(dev, 0); drivers/tty/serial/sh-sci.c: sciport->gpios =
mctrl_gpio_init(&sciport->port, 0);Atmel, ARM, ETRAX, ARM, ARM, Super-H, all have GPIOLIB. Right now no x86, correct?
They actually all even do things like this in
Kconfig:
Quoted 7 lines
config
SERIAL_ATMEL
(...)
selectSERIAL_MCTRL_GPIOif GPIOLIBWhat stops us from removing all the stubs in
drivers/tty/serial/serial_mctrl_gpio.h
and just makeSERIAL_MCTRL_GPIOdepends on GPIOLIB?
Would be ok for me, too. People seem to object to that though.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
Hi Linus,
Quoted 47 lines · Linus Walleij
Quoted 16 lines · Uwe Kleine-K?nig
Quoted 8 lines · Geert Uytterhoeven
On Mon, Mar 6, 2017 at 10:30 AM, Uwe Kleine-K?nig
Quoted 7 lines
I wouldn't want to code this in each driver (something like:
if (IS_ENABLED(GPIOLIB) || device_is_instantiated_by_dt(dev) || device_is_instantiated_by_acpi(dev)) gpios = mctrl_gpio_init(...); else gpios = NULL;Quoted 6 lines
Quoted 3 lines
). Putting this into GPIOLIB is the right approach, and so this is another argument for HALFGPIOLIB. This would fix
mctrl_gpio_initen passant.Do we have platforms where DT=y || ACPI=y, but GPIOLIB=n? Ah, x86 ;-)
Quoted 8 lines
Yeah, and I think rm -r
arch/x86won't be acceptable :-) I assume you can also configure some arm or powerpc systems without GPIOLIB.Quoted 2 lines
Anyway, for
sh-sci.c, platforms either have DT and GPIOLIB, or they do not need mctrl-gpio.So we're in agreement now that HALFGPIOLIB is the way to go? Linus, what do you think?
OK modem lines over GPIO.
So the problem is that GPIOLIB is needed (obviously) for
mctrl_gpio_init()to work properly, and then there are some stubs indrivers/tty/serial/serial_mctrl_gpio.h
for !GPIOLIB.And this whole discussion is all about that !GPIOLIB case really, whether DT, ACPI, SFI or board files machine data is used doesn't really matter.
We're talking about:
Quoted 1 line
git grep
mctrl_gpio_init
drivers/tty/serial/atmel_serial.c:atmel_port->gpios=mctrl_gpio_init(&atmel_port->uart, 0);drivers/tty/serial/clps711x.c:s->gpios=mctrl_gpio_init_noauto(&pdev->dev, 0);drivers/tty/serial/etraxfs-uart.c:up->gpios=mctrl_gpio_init_noauto(&pdev->dev, 0);
Quoted 7 lines
drivers/tty/serial/imx.c: sport->gpios = mctrl_gpio_init(&sport->port, 0); drivers/tty/serial/mxs-auart.c: s->gpios = mctrl_gpio_init_noauto(dev, 0); drivers/tty/serial/sh-sci.c: sciport->gpios =
mctrl_gpio_init(&sciport->port, 0);Atmel, ARM, ETRAX, ARM, ARM, Super-H, all have GPIOLIB. Right now no x86, correct?
It's not that black-and-white. Some of SuperH have GPIOLIB, other parts don't.
Quoted 9 lines
They actually all even do things like this in
Kconfig:config
SERIAL_ATMEL
(...)
selectSERIAL_MCTRL_GPIOif GPIOLIBWhat stops us from removing all the stubs in
drivers/tty/serial/serial_mctrl_gpio.h
and just makeSERIAL_MCTRL_GPIOdepends on GPIOLIB?
Removing the stubs implies adding #ifdefs to the drivers that need to handle the !SERIAL_MCTRL_GPIO case.
E.g. I don't want to break the sh-sci serial driver on SuperH platforms that
(a) don't select GPIOLIB, and
(b) don't use mtrl_gpio.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Hi Linus,
Quoted 10 lines · Geert Uytterhoeven
Quoted 9 lines
They actually all even do things like this in
Kconfig:config
SERIAL_ATMEL
(...)
selectSERIAL_MCTRL_GPIOif GPIOLIBWhat stops us from removing all the stubs in
drivers/tty/serial/serial_mctrl_gpio.h
and just makeSERIAL_MCTRL_GPIOdepends on GPIOLIB?
Quoted 6 lines
Removing the stubs implies adding #ifdefs to the drivers that need to handle the !SERIAL_MCTRL_GPIO case.
E.g. I don't want to break the sh-sci serial driver on SuperH platforms that
(a) don't select GPIOLIB, and
(b) don't usemtrl_gpio.
Alternatively, after commit 22c403676dbbb7c6 ("gpio: return NULL from gpiod_get_optional when GPIOLIB is disabled") we might just drop the dependency of SERIAL_MCTRL_GPIO on GPIOLIB? Then no special handling is needed in drivers, as all GPIOs will just be considered not present.
Documentation/gpio/consumer.txt rightfully sates:
| Note that gpio_get*_optional() functions (and their managed variants), unlike | the rest of gpiolib API, also return NULL when gpiolib support is disabled. | This is helpful to driver authors, since they do not need to special case | -ENOSYS return codes. System integrators should however be careful to enable | gpiolib on systems that need it.
drivers/tty/serial/serial_mctrl_gpio.o already compiles fine if CONFIG_GPIOLIB=n, which reduces its size by ca. 25%.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Quoted 2 lines · Geert Uytterhoeven
drivers/tty/serial/serial_mctrl_gpio.oalready compiles fine ifCONFIG_GPIOLIB=n, which reduces its size by ca. 25%.
That is: after removing the #ifdef and dummies in serial_mctrl_gpio.h
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Hello Geert,
Quoted 6 lines · Geert Uytterhoeven
Documentation/gpio/consumer.txtrightfully sates:| Note that gpio_get*_optional() functions (and their managed variants), unlike | the rest of gpiolib API, also return NULL when gpiolib support is disabled. | This is helpful to driver authors, since they do not need to special case | -ENOSYS return codes. System integrators should however be careful to enable | gpiolib on systems that need it.
I cannot find this paragraph in Documentation/gpio/consumer.txt:
$ git grep -e 'ENOSYS' v4.11-rc3 -- Documentation/gpio/ <void>
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
Hi Uwe,
Quoted 8 lines · Uwe Kleine-K?nig
Quoted 6 lines · Geert Uytterhoeven
Documentation/gpio/consumer.txtrightfully sates:| Note that gpio_get*_optional() functions (and their managed variants), unlike | the rest of gpiolib API, also return NULL when gpiolib support is disabled. | This is helpful to driver authors, since they do not need to special case | -ENOSYS return codes. System integrators should however be careful to enable | gpiolib on systems that need it.
Quoted 4 lines
I cannot find this paragraph in
Documentation/gpio/consumer.txt:$ git grep -e 'ENOSYS' v4.11-rc3 -- Documentation/gpio/ <void>
It was added by commit 22c403676dbbb7c6 ("gpio: return NULL from gpiod_get_optional when GPIOLIB is disabled")
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Hello Geert,
Quoted 10 lines · Geert Uytterhoeven
Quoted 8 lines · Uwe Kleine-K?nig
Quoted 6 lines · Geert Uytterhoeven
Documentation/gpio/consumer.txtrightfully sates:| Note that gpio_get*_optional() functions (and their managed variants), unlike | the rest of gpiolib API, also return NULL when gpiolib support is disabled. | This is helpful to driver authors, since they do not need to special case | -ENOSYS return codes. System integrators should however be careful to enable | gpiolib on systems that need it.
Quoted 7 lines
Quoted 4 lines
I cannot find this paragraph in
Documentation/gpio/consumer.txt:$ git grep -e 'ENOSYS' v4.11-rc3 -- Documentation/gpio/ <void>It was added by commit
22c403676dbbb7c6("gpio: return NULL fromgpiod_get_optionalwhen GPIOLIB is disabled")
Ah, that's in next.
I still think this is wrong and I'm a bit disappointed that Linus merged this patch (without saying so in the thread even) as I thought Linus and I agreed on this being a bad idea.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
Quoted 18 lines · Uwe Kleine-K?nig
Hello Geert,
Quoted 15 lines · Geert Uytterhoeven
Quoted 12 lines · Uwe Kleine-K?nig
Quoted 6 lines · Geert Uytterhoeven
Documentation/gpio/consumer.txtrightfully sates:| Note that gpio_get*_optional() functions (and their managed variants), unlike | the rest of gpiolib API, also return NULL when gpiolib support is disabled. | This is helpful to driver authors, since they do not need to special case | -ENOSYS return codes. System integrators should however be careful to enable | gpiolib on systems that need it.I cannot find this paragraph in
Documentation/gpio/consumer.txt:$ git grep -e 'ENOSYS' v4.11-rc3 -- Documentation/gpio/ <void>
Quoted 8 lines
Quoted 2 lines
It was added by commit
22c403676dbbb7c6("gpio: return NULL fromgpiod_get_optionalwhen GPIOLIB is disabled")Ah, that's in next.
I still think this is wrong and I'm a bit disappointed that Linus merged this patch (without saying so in the thread even) as I thought Linus and I agreed on this being a bad idea.
I think it is not good, but what we have before this patch is worse.
I.e. it is the lesser evil.
Before this patch the API is inconsistent: it gives NULL if GPIOLIB is defined and -ENOSYS if GPIOLIB is not defined.
After this patch it gives NULL in both cases, and that is at least consistent.
It would be great if someone steps in and fix it so as to return relevant errors (or error pointers rather) in both cases. However I guess it will lead a bunch of fallouts in the consumers, albeit they are not super-many.
Yours,
Linus Walleij
Quoted 29 lines · Linus Walleij
Quoted 18 lines · Uwe Kleine-K?nig
Hello Geert,
Quoted 15 lines · Geert Uytterhoeven
Quoted 12 lines · Uwe Kleine-K?nig
Quoted 6 lines · Geert Uytterhoeven
Documentation/gpio/consumer.txtrightfully sates:| Note that gpio_get*_optional() functions (and their managed variants), unlike | the rest of gpiolib API, also return NULL when gpiolib support is disabled. | This is helpful to driver authors, since they do not need to special case | -ENOSYS return codes. System integrators should however be careful to enable | gpiolib on systems that need it.I cannot find this paragraph in
Documentation/gpio/consumer.txt:$ git grep -e 'ENOSYS' v4.11-rc3 -- Documentation/gpio/ <void>Quoted 8 lines
Quoted 2 lines
It was added by commit
22c403676dbbb7c6("gpio: return NULL fromgpiod_get_optionalwhen GPIOLIB is disabled")Ah, that's in next.
I still think this is wrong and I'm a bit disappointed that Linus merged this patch (without saying so in the thread even) as I thought Linus and I agreed on this being a bad idea.
Quoted 6 lines
I think it is not good, but what we have before this patch is worse.
I.e. it is the lesser evil.
Before this patch the API is inconsistent: it gives NULL if GPIOLIB is defined and
-ENOSYSif GPIOLIB is not defined.
So old is: it worked as intended with GPIOLIB and produced an error without GPIOLIB even if no GPIO is there and NULL would be right.
Quoted 2 lines
After this patch it gives NULL in both cases, and that is at least consistent.
And new is: with GPIOLIB it still works as intended and gives you NULL even if a GPIO is there and so -ENOSYS would be right.
I admit that most of the time with GPIOLIB NULL is the right answer because probably there is no GPIO to handle. But if there is a GPIO you run in hard to debug problems instead of being able to see the error code and act accordingly.
write(2) and close(2) succeed most of the time, too. Still it's not a good idea to not check the return value. Or let the kernel return success unconditionally.
So you exchanged many obvious and easy to fix problems with a few hard ones. I don't agree that's a good idea, but you seem to be willing to try it. Good luck.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
Hi Uwe,
Quoted 35 lines · Uwe Kleine-K?nig
Quoted 27 lines · Linus Walleij
Quoted 16 lines · Uwe Kleine-K?nig
Quoted 15 lines · Geert Uytterhoeven
Quoted 12 lines · Uwe Kleine-K?nig
Quoted 6 lines · Geert Uytterhoeven
Documentation/gpio/consumer.txtrightfully sates:| Note that gpio_get*_optional() functions (and their managed variants), unlike | the rest of gpiolib API, also return NULL when gpiolib support is disabled. | This is helpful to driver authors, since they do not need to special case | -ENOSYS return codes. System integrators should however be careful to enable | gpiolib on systems that need it.I cannot find this paragraph in
Documentation/gpio/consumer.txt:$ git grep -e 'ENOSYS' v4.11-rc3 -- Documentation/gpio/ <void>Quoted 8 lines
Quoted 2 lines
It was added by commit
22c403676dbbb7c6("gpio: return NULL fromgpiod_get_optionalwhen GPIOLIB is disabled")Ah, that's in next.
I still think this is wrong and I'm a bit disappointed that Linus merged this patch (without saying so in the thread even) as I thought Linus and I agreed on this being a bad idea.
Quoted 6 lines
I think it is not good, but what we have before this patch is worse.
I.e. it is the lesser evil.
Before this patch the API is inconsistent: it gives NULL if GPIOLIB is defined and
-ENOSYSif GPIOLIB is not defined.
Quoted 8 lines
So old is: it worked as intended with GPIOLIB and produced an error without GPIOLIB even if no GPIO is there and NULL would be right.
Quoted 2 lines
After this patch it gives NULL in both cases, and that is at least consistent.
And new is: with GPIOLIB it still works as intended and gives you NULL even if a GPIO is there and so
-ENOSYSwould be right.
If I forget to enable a driver, the corresponding class device is also not there.
Quoted 4 lines
I admit that most of the time with GPIOLIB NULL is the right answer because probably there is no GPIO to handle. But if there is a GPIO you run in hard to debug problems instead of being able to see the error code and act accordingly.
But having the error breaks setups where the GPIO is optional and does not exist.
Make sure to enable all drivers and subsystems you need when building your kernel. That's always true. And may indeed be hard to debug (e.g. what kernel options do I need to make systemd work?).
Quoted 3 lines
write(2) and close(2) succeed most of the time, too. Still it's not a good idea to not check the return value. Or let the kernel return success unconditionally.
Writing all bytes passed in the buffer is "optional" in another sense than an "optional" GPIO: you must retry the write, while you can continue if an optional GPIO is not present.
Quoted 3 lines
So you exchanged many obvious and easy to fix problems with a few hard ones. I don't agree that's a good idea, but you seem to be willing to try it. Good luck.
Yeah, before drivers had to explicitly ignore -ENOSYS if they want to support platforms with and without GPIOLIB. Bad...
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Hello,
Quoted 2 lines · Geert Uytterhoeven
But having the error breaks setups where the GPIO is optional and does not exist.
so the right way forward is to check harder in the situation where -ENOSYS was returned before to determine if there is really no GPIO to be used. "Oh, there are hints that there is no GPIO (GPIOLIB=n), so lets assume there isn't." is wrong.
Can we please properly fix the problem instead of papering over it?
Quoted 3 lines
Make sure to enable all drivers and subsystems you need when building your kernel. That's always true. And may indeed be hard to debug (e.g. what kernel options do I need to make systemd work?).
It's worse here. If you forget to enable a driver the device isn't bound and that's obvious to diagnose. When ignoring an optional GPIO there might be a device that claims to work but fails to do so. (e.g. you write to memory, write() returns 0, but the data never landed there.)
Quoted 7 lines
Quoted 3 lines
write(2) and close(2) succeed most of the time, too. Still it's not a good idea to not check the return value. Or let the kernel return success unconditionally.
Writing all bytes passed in the buffer is "optional" in another sense than an "optional" GPIO: you must retry the write, while you can continue if an optional GPIO is not present.
And that is the point. You can continue *iff* the optional GPIO is not present. The patch in question removes the ability to determine if that GPIO is present and claims it is not present.
Quoted 6 lines
Quoted 3 lines
So you exchanged many obvious and easy to fix problems with a few hard ones. I don't agree that's a good idea, but you seem to be willing to try it. Good luck.
Yeah, before drivers had to explicitly ignore
-ENOSYSif they want to support platforms with and without GPIOLIB. Bad...
Doing things right is sometimes not maximally easy. But that is no excuse to do it wrong.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
Hi Uwe,
Quoted 13 lines · Uwe Kleine-K?nig
Quoted 3 lines
Make sure to enable all drivers and subsystems you need when building your kernel. That's always true. And may indeed be hard to debug (e.g. what kernel options do I need to make systemd work?).
It's worse here. If you forget to enable a driver the device isn't bound and that's obvious to diagnose. When ignoring an optional GPIO there might be a device that claims to work but fails to do so. (e.g. you write to memory,
write()returns 0, but the data never landed there.)Quoted 4 lines
Quoted 3 lines
write(2) and close(2) succeed most of the time, too. Still it's not a good idea to not check the return value. Or let the kernel return success unconditionally.
Quoted 7 lines
Quoted 3 lines
Writing all bytes passed in the buffer is "optional" in another sense than an "optional" GPIO: you must retry the write, while you can continue if an optional GPIO is not present.
And that is the point. You can continue *iff* the optional GPIO is not present. The patch in question removes the ability to determine if that GPIO is present and claims it is not present.
If you forget to enable a driver/subsystem, you sometimes cannot determine if the device is present or not neither.
Hence it boils down to "knowing" if there is a GPIO or not.
So, when can there be a GPIO?
1. The GPIO is described in DT.
=> Not an issue, as DT GPIO implies GPIOLIB,
2. The GPIO is described in legacy platform data.
=> The platform code should make sure GPIOLIB is selected when needed.
Issue solved?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Quoted 28 lines · Geert Uytterhoeven
Hi Uwe,
Quoted 13 lines · Uwe Kleine-K?nig
Quoted 3 lines
Make sure to enable all drivers and subsystems you need when building your kernel. That's always true. And may indeed be hard to debug (e.g. what kernel options do I need to make systemd work?).
It's worse here. If you forget to enable a driver the device isn't bound and that's obvious to diagnose. When ignoring an optional GPIO there might be a device that claims to work but fails to do so. (e.g. you write to memory,
write()returns 0, but the data never landed there.)Quoted 4 lines
Quoted 3 lines
write(2) and close(2) succeed most of the time, too. Still it's not a good idea to not check the return value. Or let the kernel return success unconditionally.
Quoted 7 lines
Quoted 3 lines
Writing all bytes passed in the buffer is "optional" in another sense than an "optional" GPIO: you must retry the write, while you can continue if an optional GPIO is not present.
And that is the point. You can continue *iff* the optional GPIO is not present. The patch in question removes the ability to determine if that GPIO is present and claims it is not present.
If you forget to enable a driver/subsystem, you sometimes cannot determine if the device is present or not neither.
Quoted 8 lines
Hence it boils down to "knowing" if there is a GPIO or not.
So, when can there be a GPIO?
1. The GPIO is described in DT.
=> Not an issue, as DT GPIO implies GPIOLIB,
2. The GPIO is described in legacy platform data.
=> The platform code should make sure GPIOLIB is selected when needed.Issue solved?
I like it better to not rely on platform code to do the right thing.
Maybe we can make gpiod_get_optional look like this:
if (!dev->of_node && isnt_a_acpi_device(dev) && !IS_ENABLED(GPIOLIB)) return NULL; else return -ENOSYS;
I don't know how isnt_a_acpi_device looks like, probably it involves CONFIG_ACPI and/or dev->acpi_node.
This should be safe and still comfortable for legacy platforms, isn't it?
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
Hi Uwe,
Quoted 34 lines · Uwe Kleine-K?nig
Quoted 33 lines · Geert Uytterhoeven
Quoted 13 lines · Uwe Kleine-K?nig
Quoted 3 lines
Make sure to enable all drivers and subsystems you need when building your kernel. That's always true. And may indeed be hard to debug (e.g. what kernel options do I need to make systemd work?).
It's worse here. If you forget to enable a driver the device isn't bound and that's obvious to diagnose. When ignoring an optional GPIO there might be a device that claims to work but fails to do so. (e.g. you write to memory,
write()returns 0, but the data never landed there.)Quoted 4 lines
Quoted 3 lines
write(2) and close(2) succeed most of the time, too. Still it's not a good idea to not check the return value. Or let the kernel return success unconditionally.
Quoted 7 lines
Quoted 3 lines
Writing all bytes passed in the buffer is "optional" in another sense than an "optional" GPIO: you must retry the write, while you can continue if an optional GPIO is not present.
And that is the point. You can continue *iff* the optional GPIO is not present. The patch in question removes the ability to determine if that GPIO is present and claims it is not present.
If you forget to enable a driver/subsystem, you sometimes cannot determine if the device is present or not neither.
Hence it boils down to "knowing" if there is a GPIO or not.
So, when can there be a GPIO?
1. The GPIO is described in DT.
=> Not an issue, as DT GPIO implies GPIOLIB,
2. The GPIO is described in legacy platform data.
=> The platform code should make sure GPIOLIB is selected when needed.
Quoted 3 lines
Quoted 1 line
Issue solved?
I like it better to not rely on platform code to do the right thing.
;-)
Quoted 11 lines
Maybe we can make
gpiod_get_optionallook like this:if (!dev->of_node && isnt_a_acpi_device(dev) && !IS_ENABLED(GPIOLIB)) return NULL; else return -ENOSYS;I don't know how
isnt_a_acpi_devicelooks like, probably it involvesCONFIG_ACPIand/ordev->acpi_node.This should be safe and still comfortable for legacy platforms, isn't it?
Yes, that should do the trick.
No feedback from me about ACPI.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Quoted 11 lines · Uwe Kleine-K?nig
Maybe we can make
gpiod_get_optionallook like this:if (!dev->of_node && isnt_a_acpi_device(dev) && !IS_ENABLED(GPIOLIB)) return NULL; else return -ENOSYS;I don't know how
isnt_a_acpi_devicelooks like, probably it involvesCONFIG_ACPIand/ordev->acpi_node.This should be safe and still comfortable for legacy platforms, isn't it?
I like the looks of this.
Can we revert Dmitry's patch and apply something like this instead?
Dmitry, how do you feel about this?
Yours,
Linus Walleij
Quoted 13 lines · Linus Walleij
Quoted 10 lines · Uwe Kleine-K?nig
Maybe we can make
gpiod_get_optionallook like this:if (!dev->of_node && isnt_a_acpi_device(dev) && !IS_ENABLED(GPIOLIB)) return NULL; else return -ENOSYS;I don't know how
isnt_a_acpi_devicelooks like, probably it involvesCONFIG_ACPIand/ordev->acpi_node.
Quoted 7 lines
Quoted 1 line
This should be safe and still comfortable for legacy platforms, isn't it?
I like the looks of this.
Can we revert Dmitry's patch and apply something like this instead?
Dmitry, how do you feel about this?
I frankly do not see the point. It still makes driver code more complex for no good reason. I also think that not having optional GPIO is not an error, so returning value from error space is not correct. NULL is value from another space altogether.
Uwe seems to be concerned about case that I find extremely unlikely. We are talking about a system that does not have GPIO support and behaves just fine, with the exception that it actually has (physically) a *single* GPIO, and that GPIO happens to be optional in a single driver, but in this particular system is actually needed (but that need manifests in a non-obvious way). And we have system integrator that has no idea what they are doing (no schematic, etc).
I think that if there is one optional GPIO there will be mandatiry GPIOs in such system as well and selection of GPIOLIB will be forced early on in board bringup.
Thanks.
Signature · 1 line
Dmitry
Quoted 35 lines · Dmitry Torokhov
Quoted 13 lines · Linus Walleij
Quoted 10 lines · Uwe Kleine-K?nig
Maybe we can make
gpiod_get_optionallook like this:if (!dev->of_node && isnt_a_acpi_device(dev) && !IS_ENABLED(GPIOLIB)) return NULL; else return -ENOSYS;I don't know how
isnt_a_acpi_devicelooks like, probably it involvesCONFIG_ACPIand/ordev->acpi_node.Quoted 7 lines
Quoted 1 line
This should be safe and still comfortable for legacy platforms, isn't it?
I like the looks of this.
Can we revert Dmitry's patch and apply something like this instead?
Dmitry, how do you feel about this?
I frankly do not see the point. It still makes driver code more complex for no good reason. I also think that not having optional GPIO is not an error, so returning value from error space is not correct. NULL is value from another space altogether.
Uwe seems to be concerned about case that I find extremely unlikely. We are talking about a system that does not have GPIO support and behaves just fine, with the exception that it actually has (physically) a *single* GPIO, and that GPIO happens to be optional in a single driver, but in this particular system is actually needed (but that need manifests in a non-obvious way). And we have system integrator that has no idea what they are doing (no schematic, etc).
Quoted 3 lines
I think that if there is one optional GPIO there will be mandatiry GPIOs in such system as well and selection of GPIOLIB will be forced early on in board bringup.
One more thing: if we keep reporting -ENOSYS in case of !CONFIG_GPIOLIB, then most of the non platform-sepcific drivers will eventually gain code silently coping with this -ENOSYS:
data->gpiod = gpiod_getptional(...);
if (IS_ERR(data->gpiod)) {
error = PTR_ERR(data->gpiod);
if (error != -ENOSYS)
return error;
data->gpiod = NULL; /* This GPIO _is_ optional */
}which will negate Uwe's claim that it will help debugging issues.
Thanks.
Signature · 1 line
Dmitry
Quoted 17 lines · Dmitry Torokhov
Quoted 16 lines · Dmitry Torokhov
Quoted 15 lines · Linus Walleij
Quoted 11 lines · Uwe Kleine-K?nig
Maybe we can make
gpiod_get_optionallook like this:if (!dev->of_node && isnt_a_acpi_device(dev) && !IS_ENABLED(GPIOLIB)) return NULL; else return -ENOSYS;I don't know how
isnt_a_acpi_devicelooks like, probably it involvesCONFIG_ACPIand/ordev->acpi_node.This should be safe and still comfortable for legacy platforms, isn't it?
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
I like the looks of this.
Can we revert Dmitry's patch and apply something like this instead?
Dmitry, how do you feel about this?
I frankly do not see the point. It still makes driver code more complex
Note that this code is in the gpio header, and not in driver code. So the driver just does
gpiod = gpiod_get_optional(...) if (IS_ERR(gpiod)) return PTR_ERR(gpiod);
(as it is supposed to do now). I think that's nice.
Quoted 3 lines
Quoted 3 lines
for no good reason. I also think that not having optional GPIO is not an error, so returning value from error space is not correct. NULL is value from another space altogether.
It seems you didn't understand my concern.
Quoted 7 lines
Quoted 7 lines
Uwe seems to be concerned about case that I find extremely unlikely. We are talking about a system that does not have GPIO support and behaves just fine, with the exception that it actually has (physically) a *single* GPIO, and that GPIO happens to be optional in a single driver, but in this particular system is actually needed (but that need manifests in a non-obvious way). And we have system integrator that has no idea what they are doing (no schematic, etc).
IMHO this is not an excuse to have lax error checking.
Quoted 8 lines
Quoted 3 lines
I think that if there is one optional GPIO there will be mandatiry GPIOs in such system as well and selection of GPIOLIB will be forced early on in board bringup.
One more thing: if we keep reporting
-ENOSYSin case of !CONFIG_GPIOLIB, then most of the non platform-sepcific drivers will eventually gain code silently coping with this-ENOSYS:
Quoted 7 lines
data->gpiod = gpiod_getptional(...);
if (IS_ERR(data->gpiod)) {
error = PTR_ERR(data->gpiod);
if (error != -ENOSYS)
return error;
data->gpiod = NULL; /* This GPIO _is_ optional */Do you agree that this is wrong? Yes, it behaves right for most cases. But there are cases where it behaves wrong and so it needs fixing.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
Quoted 26 lines · Uwe Kleine-K?nig
Quoted 17 lines · Dmitry Torokhov
Quoted 16 lines · Dmitry Torokhov
Quoted 15 lines · Linus Walleij
Quoted 11 lines · Uwe Kleine-K?nig
Maybe we can make
gpiod_get_optionallook like this:if (!dev->of_node && isnt_a_acpi_device(dev) && !IS_ENABLED(GPIOLIB)) return NULL; else return -ENOSYS;I don't know how
isnt_a_acpi_devicelooks like, probably it involvesCONFIG_ACPIand/ordev->acpi_node.This should be safe and still comfortable for legacy platforms, isn't it?
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
I like the looks of this.
Can we revert Dmitry's patch and apply something like this instead?
Dmitry, how do you feel about this?
I frankly do not see the point. It still makes driver code more complex
Quoted 8 lines
Note that this code is in the gpio header, and not in driver code. So the driver just does
gpiod = gpiod_get_optional(...) if (IS_ERR(gpiod)) return PTR_ERR(gpiod);(as it is supposed to do now). I think that's nice.
Except that it breaks if !CONFIG_GPIOLIB which is legitimate config in many cases. Can I have a DT platform or ACPI platform that does not expose any GPIOs for kernel to control and thus want to disable GPIOLIB? I can't see why not.
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
for no good reason. I also think that not having optional GPIO is not an error, so returning value from error space is not correct. NULL is value from another space altogether.
It seems you didn't understand my concern.
Likewise.
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
Uwe seems to be concerned about case that I find extremely unlikely. We are talking about a system that does not have GPIO support and behaves just fine, with the exception that it actually has (physically) a *single* GPIO, and that GPIO happens to be optional in a single driver, but in this particular system is actually needed (but that need manifests in a non-obvious way). And we have system integrator that has no idea what they are doing (no schematic, etc).
IMHO this is not an excuse to have lax error checking.
IMO it is not an error altogether, so there is no lax checking.
Quoted 15 lines
Quoted 15 lines
Quoted 4 lines
I think that if there is one optional GPIO there will be mandatiry GPIOs in such system as well and selection of GPIOLIB will be forced early on in board bringup.
One more thing: if we keep reporting
-ENOSYSin case of !CONFIG_GPIOLIB, then most of the non platform-sepcific drivers will eventually gain code silently coping with this-ENOSYS:data->gpiod = gpiod_getptional(...); if (IS_ERR(data->gpiod)) { error = PTR_ERR(data->gpiod); if (error != -ENOSYS) return error;
Quoted 4 lines
Quoted 1 line
data->gpiod = NULL; /* This GPIO _is_ optional */Do you agree that this is wrong? Yes, it behaves right for most cases. But there are cases where it behaves wrong and so it needs fixing.
I think by now it should be obvious that I do not find it wrong. In fact that is what I, as a maintainer of drivers that supposed to work on multitude of platforms, will be forced to do, if the change to stop reporting -ENOSYS gets reverted. A generic driver has no way to know that kernel configuration or firmware configuration is wrong and should not be trusted (except for piling up horrendous DMI hacks in some cases on X86).
Thanks.
Signature · 1 line
Dmitry
Hello Dmitry,
Quoted 42 lines · Dmitry Torokhov
Quoted 26 lines · Uwe Kleine-K?nig
Quoted 17 lines · Dmitry Torokhov
Quoted 16 lines · Dmitry Torokhov
Quoted 15 lines · Linus Walleij
Quoted 11 lines · Uwe Kleine-K?nig
Maybe we can make
gpiod_get_optionallook like this:if (!dev->of_node && isnt_a_acpi_device(dev) && !IS_ENABLED(GPIOLIB)) return NULL; else return -ENOSYS;I don't know how
isnt_a_acpi_devicelooks like, probably it involvesCONFIG_ACPIand/ordev->acpi_node.This should be safe and still comfortable for legacy platforms, isn't it?
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
I like the looks of this.
Can we revert Dmitry's patch and apply something like this instead?
Dmitry, how do you feel about this?
I frankly do not see the point. It still makes driver code more complex
Quoted 8 lines
Note that this code is in the gpio header, and not in driver code. So the driver just does
gpiod = gpiod_get_optional(...) if (IS_ERR(gpiod)) return PTR_ERR(gpiod);(as it is supposed to do now). I think that's nice.
Except that it breaks if !CONFIG_GPIOLIB which is legitimate config in many cases. Can I have a DT platform or ACPI platform that does not expose any GPIOs for kernel to control and thus want to disable GPIOLIB? I can't see why not.
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
for no good reason. I also think that not having optional GPIO is not an error, so returning value from error space is not correct. NULL is value from another space altogether.
It seems you didn't understand my concern.
Likewise.
OK, lets agree that we don't agree then. You think that if someone disabled GPIOLIB it should be safe to assume that there is no GPIO, I think that's wrong.
Still I think it should be possible that we agree on my suggestion to return NULL in some cases only. Here is a prototype (not even compile tested without GPIOLIB):
------->8--------
From: Uwe Kleine-K?nig <[email protected]>
Subject: [PATCH] gpiod: let get_optional return NULL in some cases with GPIOLIB disabled
People disagree if gpiod_get_optional should return NULL or ERR_PTR(-ENOSYS) if GPIOLIB is disabled. The argument for NULL is that the person who decided to disable GPIOLIB is assumed to know that there is no GPIO. The reason to stick to ERR_PTR(-ENOSYS) is that it might introduce hard to debug problems if that decision is wrong.
So this patch introduces a compromise and let gpiod_get_optional (and its variants) return NULL if the device in question cannot have an associated GPIO because it is neither instantiated by a device tree nor by ACPI.
This should handle most cases that are argued about.
--- include/linux/gpio/consumer.h | 55 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 9 deletions(-)
include/linux/gpio/consumer.h +46 -9
@@ -161,20 +161,48 @@ gpiod_get_index(struct device *dev,return ERR_PTR (-ENOSYS ); } -static inline struct gpio_desc *__must_check -gpiod_get_optional (struct device *dev,const char *con_id, -enum gpiod_flags flags) +static inline bool __gpiod_no_optional_possible (struct device *dev) { -return ERR_PTR (-ENOSYS ); +/* +* gpiod_get_optional et al can only provide a GPIO if at least one of +* the backends for specifing a GPIO is available. These are device +* tree, ACPI and gpiolib's lookup tables. The latter isn't available if +* GPIOLIB is disabled (which is the case here). +* So if the provided device is unrelated to device tree and ACPI, we +* can be sure that there is no optional GPIO and let gpiod_get_optional +* safely return NULL. +* Otherwise there is still a chance that there is no GPIO but we cannot +* be sure without having to enable a part of GPIOLIB (i.e. the lookup +* part). So lets play safe and return an error. (Though there are also +* arguments that returning NULL then would be beneficial.) +*/ + +if (IS_ENABLED (CONFIG_OF ) && dev && dev->of_node) +return false; + +if (IS_ENABLED (CONFIG_ACPI ) && dev &&ACPI_COMPANION (dev)) +return false; + +return true; }static inline struct gpio_desc *__must_check gpiod_get_index_optional (struct device *dev,const char *con_id,unsigned int index,enum gpiod_flags flags) { +if (__gpiod_no_optional_possible (dev)) +return NULL ; +return ERR_PTR (-ENOSYS ); } +static inline struct gpio_desc *__must_check +gpiod_get_optional (struct device *dev,const char *con_id, +enum gpiod_flags flags) +{ +return gpiod_get_index_optional (dev, con_id,0 , flags); +} +static inline struct gpio_descs *__must_check gpiod_get_array (struct device *dev,const char *con_id,enum gpiod_flags flags)
@@ -186,6 +214,9 @@ static inline struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev, const char *con_id, enum gpiod_flags flags) { + if (__gpiod_no_optional_possible(dev)) + return NULL; + return ERR_PTR(-ENOSYS); }
@@ -223,17 +254,20 @@ devm_gpiod_get_index(struct device *dev, }static inline struct gpio_desc *__must_check -devm_gpiod_get_optional (struct device *dev,const char *con_id, -enum gpiod_flags flags) +devm_gpiod_get_index_optional (struct device *dev,const char *con_id, +unsigned int index,enum gpiod_flags flags) { +if (__gpiod_no_optional_possible (dev)) +return NULL ; +return ERR_PTR (-ENOSYS ); }static inline struct gpio_desc *__must_check -devm_gpiod_get_index_optional (struct device *dev,const char *con_id, -unsigned int index,enum gpiod_flags flags) +devm_gpiod_get_optional (struct device *dev,const char *con_id, +enum gpiod_flags flags) { -return ERR_PTR (-ENOSYS ); +return devm_gpiod_get_index_optional (dev, con_id,0 , flags); } static inline struct gpio_descs *__must_check
@@ -247,6 +281,9 @@ static inline struct gpio_descs *__must_check devm_gpiod_get_array_optional(struct device *dev, const char *con_id, enum gpiod_flags flags) { + if (__gpiod_no_optional_possible(dev)) + return NULL; + return ERR_PTR(-ENOSYS); }
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
Hi Uwe,
Quoted 41 lines · Uwe Kleine-K?nig
From: Uwe Kleine-K?nig <[email protected]>
Subject: [PATCH] gpiod: letget_optionalreturn NULL in some cases with GPIOLIB disabledPeople disagree if
gpiod_get_optionalshould return NULL orERR_PTR(-ENOSYS)if GPIOLIB is disabled. The argument for NULL is that the person who decided to disable GPIOLIB is assumed to know that there is no GPIO. The reason to stick toERR_PTR(-ENOSYS)is that it might introduce hard to debug problems if that decision is wrong.So this patch introduces a compromise and let
gpiod_get_optional(and its variants) return NULL if the device in question cannot have an associated GPIO because it is neither instantiated by a device tree nor by ACPI.This should handle most cases that are argued about.
Signed-off-by Uwe Kleine-K?nig <[email protected]>--- include/linux/gpio/consumer.h | 55 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 9 deletions(-)include/linux/gpio/consumer.h +7
-4@@ -161,20 +161,48 @@ gpiod_get_index(struct device *dev,return ERR_PTR (-ENOSYS ); } -static inline struct gpio_desc *__must_check -gpiod_get_optional (struct device *dev,const char *con_id, -enum gpiod_flags flags) +static inline bool __gpiod_no_optional_possible (struct device *dev) { -return ERR_PTR (-ENOSYS ); +/* +* gpiod_get_optional et al can only provide a GPIO if at least one of +* the backends for specifing a GPIO is available. These are device +* tree, ACPI and gpiolib's lookup tables. The latter isn't available if +* GPIOLIB is disabled (which is the case here). +* So if the provided device is unrelated to device tree and ACPI, we
include/linux/gpio/consumer.h gpiod_get_index(struct device *dev, · line 181
Quoted 10 lines
include/linux/gpio/consumer.h +10
-0+* can be sure that there is no optional GPIO and let gpiod_get_optional +* safely return NULL. +* Otherwise there is still a chance that there is no GPIO but we cannot +* be sure without having to enable a part of GPIOLIB (i.e. the lookup +* part). So lets play safe and return an error. (Though there are also +* arguments that returning NULL then would be beneficial.) +*/ + +if (IS_ENABLED (CONFIG_OF ) && dev && dev->of_node) +return false;
At first sight, I though this was OK:
1. On ARM with DT, we can assume CONFIG_GPIOLOB=y.
2. I managed to configure an SH kernel with CONFIG_GPIOLOB=n, CONFIG_OF=y, and CONFIG_SERIAL_SH_SCI=y, but since SH boards with SH-SCI UARTs do not use DT (yet), the check for dev->of_node (false) should handle that.
3. However, I managed to do the same for h8300, which does use DT. Hence if mctrl_gpio would start relying on gpiod_get_optional(), this would break the sh-sci driver on h8300 :-(
Note that h8300 doesn't have any GPIO drivers (yet?), so CONFIG_GPIPOLIB=n makes perfect sense!
So I'm afraid the only option is to always return NULL, and put the responsability on the shoulders of the system integrator...
include/linux/gpio/consumer.h gpiod_get_index(struct device *dev, · line 184
Quoted 2 lines
include/linux/gpio/consumer.h +2
-0+if (IS_ENABLED (CONFIG_ACPI ) && dev &&ACPI_COMPANION (dev)) +return false;
No comments about the ACPI case.
include/linux/gpio/consumer.h gpiod_get_index(struct device *dev, · line 196
Quoted 8 lines
include/linux/gpio/consumer.h +3
-0static inline struct gpio_desc *__must_check gpiod_get_index_optional (struct device *dev,const char *con_id,unsigned int index,enum gpiod_flags flags) { +if (__gpiod_no_optional_possible (dev)) +return NULL ; +return ERR_PTR (-ENOSYS );
Regardless of the above, given you use the exact same construct in four locations, what about letting __gpiod_no_optional_possible() return the NULL or ERR_PTR itself, and renaming it to e.g. __gpiod_no_optional_return_value()?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Hello Geert,
Quoted 63 lines · Geert Uytterhoeven
Quoted 41 lines · Uwe Kleine-K?nig
From: Uwe Kleine-K?nig <[email protected]>
Subject: [PATCH] gpiod: letget_optionalreturn NULL in some cases with GPIOLIB disabledPeople disagree if
gpiod_get_optionalshould return NULL orERR_PTR(-ENOSYS)if GPIOLIB is disabled. The argument for NULL is that the person who decided to disable GPIOLIB is assumed to know that there is no GPIO. The reason to stick toERR_PTR(-ENOSYS)is that it might introduce hard to debug problems if that decision is wrong.So this patch introduces a compromise and let
gpiod_get_optional(and its variants) return NULL if the device in question cannot have an associated GPIO because it is neither instantiated by a device tree nor by ACPI.This should handle most cases that are argued about.
Signed-off-by Uwe Kleine-K?nig <[email protected]>--- include/linux/gpio/consumer.h | 55 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 9 deletions(-)include/linux/gpio/consumer.h +7
-4@@ -161,20 +161,48 @@ gpiod_get_index(struct device *dev,return ERR_PTR (-ENOSYS ); } -static inline struct gpio_desc *__must_check -gpiod_get_optional (struct device *dev,const char *con_id, -enum gpiod_flags flags) +static inline bool __gpiod_no_optional_possible (struct device *dev) { -return ERR_PTR (-ENOSYS ); +/* +* gpiod_get_optional et al can only provide a GPIO if at least one of +* the backends for specifing a GPIO is available. These are device +* tree, ACPI and gpiolib's lookup tables. The latter isn't available if +* GPIOLIB is disabled (which is the case here). +* So if the provided device is unrelated to device tree and ACPI, we include/linux/gpio/consumer.h gpiod_get_index(struct device *dev, · line 181
Quoted 10 lines
include/linux/gpio/consumer.h +10
-0+* can be sure that there is no optional GPIO and let gpiod_get_optional +* safely return NULL. +* Otherwise there is still a chance that there is no GPIO but we cannot +* be sure without having to enable a part of GPIOLIB (i.e. the lookup +* part). So lets play safe and return an error. (Though there are also +* arguments that returning NULL then would be beneficial.) +*/ + +if (IS_ENABLED (CONFIG_OF ) && dev && dev->of_node) +return false;At first sight, I though this was OK:
1. On ARM with DT, we can assume
CONFIG_GPIOLOB=y.2. I managed to configure an SH kernel with
CONFIG_GPIOLOB=n,CONFIG_OF=y, andCONFIG_SERIAL_SH_SCI=y, but since SH boards with SH-SCI UARTs do not use DT (yet), the check fordev->of_node(false) should handle that.
Quoted 5 lines
3. However, I managed to do the same for h8300, which does use DT. Hence if
mctrl_gpiowould start relying ongpiod_get_optional(), this would break the sh-sci driver on h8300 :-(
Note that h8300 doesn't have any GPIO drivers (yet?), soCONFIG_GPIPOLIB=nmakes perfect sense!
Thanks for your efforts.
Quoted 2 lines
So I'm afraid the only option is to always return NULL, and put the responsability on the shoulders of the system integrator...
The gpio lines could be provided by an i2c gpio adapter, right? So IMHO you don't need platform gpios to justify -ENODEV. So I guess that's a case where we don't come to an agreement.
Quoted 14 lines
include/linux/gpio/consumer.h gpiod_get_index(struct device *dev, · line 184
Quoted 2 lines
include/linux/gpio/consumer.h +2
-0+if (IS_ENABLED (CONFIG_ACPI ) && dev &&ACPI_COMPANION (dev)) +return false;No comments about the ACPI case.
include/linux/gpio/consumer.h gpiod_get_index(struct device *dev, · line 196
Quoted 8 lines
include/linux/gpio/consumer.h +3
-0static inline struct gpio_desc *__must_check gpiod_get_index_optional (struct device *dev,const char *con_id,unsigned int index,enum gpiod_flags flags) { +if (__gpiod_no_optional_possible (dev)) +return NULL ; +return ERR_PTR (-ENOSYS );
Quoted 3 lines
Regardless of the above, given you use the exact same construct in four locations, what about letting
__gpiod_no_optional_possible()return the NULL orERR_PTRitself, and renaming it to e.g.__gpiod_no_optional_return_value()?
I thought about that but didn't find a good name and so considered it more clear this way. Another optimisation would be to unconditionally define get_optional in terms of get_index_optional which would simplify my patch a bit.
I'd consider __gpiod_optional_return_value a better name than __gpiod_no_optional_return_value but I'm still not convinced.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
Hi Uwe,
Quoted 64 lines · Uwe Kleine-K?nig
Quoted 63 lines · Geert Uytterhoeven
Quoted 41 lines · Uwe Kleine-K?nig
From: Uwe Kleine-K?nig <[email protected]>
Subject: [PATCH] gpiod: letget_optionalreturn NULL in some cases with GPIOLIB disabledPeople disagree if
gpiod_get_optionalshould return NULL orERR_PTR(-ENOSYS)if GPIOLIB is disabled. The argument for NULL is that the person who decided to disable GPIOLIB is assumed to know that there is no GPIO. The reason to stick toERR_PTR(-ENOSYS)is that it might introduce hard to debug problems if that decision is wrong.So this patch introduces a compromise and let
gpiod_get_optional(and its variants) return NULL if the device in question cannot have an associated GPIO because it is neither instantiated by a device tree nor by ACPI.This should handle most cases that are argued about.
Signed-off-by Uwe Kleine-K?nig <[email protected]>--- include/linux/gpio/consumer.h | 55 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 9 deletions(-)include/linux/gpio/consumer.h +7
-4@@ -161,20 +161,48 @@ gpiod_get_index(struct device *dev,return ERR_PTR (-ENOSYS ); } -static inline struct gpio_desc *__must_check -gpiod_get_optional (struct device *dev,const char *con_id, -enum gpiod_flags flags) +static inline bool __gpiod_no_optional_possible (struct device *dev) { -return ERR_PTR (-ENOSYS ); +/* +* gpiod_get_optional et al can only provide a GPIO if at least one of +* the backends for specifing a GPIO is available. These are device +* tree, ACPI and gpiolib's lookup tables. The latter isn't available if +* GPIOLIB is disabled (which is the case here). +* So if the provided device is unrelated to device tree and ACPI, we include/linux/gpio/consumer.h gpiod_get_index(struct device *dev, · line 181
Quoted 10 lines
include/linux/gpio/consumer.h +10
-0+* can be sure that there is no optional GPIO and let gpiod_get_optional +* safely return NULL. +* Otherwise there is still a chance that there is no GPIO but we cannot +* be sure without having to enable a part of GPIOLIB (i.e. the lookup +* part). So lets play safe and return an error. (Though there are also +* arguments that returning NULL then would be beneficial.) +*/ + +if (IS_ENABLED (CONFIG_OF ) && dev && dev->of_node) +return false;At first sight, I though this was OK:
1. On ARM with DT, we can assume
CONFIG_GPIOLOB=y.2. I managed to configure an SH kernel with
CONFIG_GPIOLOB=n,CONFIG_OF=y, andCONFIG_SERIAL_SH_SCI=y, but since SH boards with SH-SCI UARTs do not use DT (yet), the check fordev->of_node(false) should handle that.
Quoted 7 lines
Quoted 5 lines
3. However, I managed to do the same for h8300, which does use DT. Hence if
mctrl_gpiowould start relying ongpiod_get_optional(), this would break the sh-sci driver on h8300 :-(
Note that h8300 doesn't have any GPIO drivers (yet?), soCONFIG_GPIPOLIB=nmakes perfect sense!Thanks for your efforts.
You're welcome.
Quoted 6 lines
Quoted 2 lines
So I'm afraid the only option is to always return NULL, and put the responsability on the shoulders of the system integrator...
The gpio lines could be provided by an i2c gpio adapter, right? So IMHO you don't need platform gpios to justify
-ENODEV. So I guess that's a case where we don't come to an agreement.
While you can enable I2C without further dependencies, no I2C GPIO expander will be offered... unless you have enabled CONFIG_GPIOLIB first.
Quoted 13 lines
Quoted 9 lines
include/linux/gpio/consumer.h gpiod_get_index(struct device *dev, · line 196
Quoted 8 lines
include/linux/gpio/consumer.h +3
-0static inline struct gpio_desc *__must_check gpiod_get_index_optional (struct device *dev,const char *con_id,unsigned int index,enum gpiod_flags flags) { +if (__gpiod_no_optional_possible (dev)) +return NULL ; +return ERR_PTR (-ENOSYS );Quoted 3 lines
Regardless of the above, given you use the exact same construct in four locations, what about letting
__gpiod_no_optional_possible()return the NULL orERR_PTRitself, and renaming it to e.g.__gpiod_no_optional_return_value()?
Quoted 7 lines
I thought about that but didn't find a good name and so considered it more clear this way. Another optimisation would be to unconditionally define
get_optionalin terms ofget_index_optionalwhich would simplify my patch a bit.I'd consider
__gpiod_optional_return_valuea better name than__gpiod_no_optional_return_valuebut I'm still not convinced.
No hard feelings about the name from my side.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Quoted 81 lines · Geert Uytterhoeven
Hi Uwe,
Quoted 64 lines · Uwe Kleine-K?nig
Quoted 63 lines · Geert Uytterhoeven
Quoted 41 lines · Uwe Kleine-K?nig
From: Uwe Kleine-K?nig <[email protected]>
Subject: [PATCH] gpiod: letget_optionalreturn NULL in some cases with GPIOLIB disabledPeople disagree if
gpiod_get_optionalshould return NULL orERR_PTR(-ENOSYS)if GPIOLIB is disabled. The argument for NULL is that the person who decided to disable GPIOLIB is assumed to know that there is no GPIO. The reason to stick toERR_PTR(-ENOSYS)is that it might introduce hard to debug problems if that decision is wrong.So this patch introduces a compromise and let
gpiod_get_optional(and its variants) return NULL if the device in question cannot have an associated GPIO because it is neither instantiated by a device tree nor by ACPI.This should handle most cases that are argued about.
Signed-off-by Uwe Kleine-K?nig <[email protected]>--- include/linux/gpio/consumer.h | 55 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 9 deletions(-)include/linux/gpio/consumer.h +7
-4@@ -161,20 +161,48 @@ gpiod_get_index(struct device *dev,return ERR_PTR (-ENOSYS ); } -static inline struct gpio_desc *__must_check -gpiod_get_optional (struct device *dev,const char *con_id, -enum gpiod_flags flags) +static inline bool __gpiod_no_optional_possible (struct device *dev) { -return ERR_PTR (-ENOSYS ); +/* +* gpiod_get_optional et al can only provide a GPIO if at least one of +* the backends for specifing a GPIO is available. These are device +* tree, ACPI and gpiolib's lookup tables. The latter isn't available if +* GPIOLIB is disabled (which is the case here). +* So if the provided device is unrelated to device tree and ACPI, we include/linux/gpio/consumer.h gpiod_get_index(struct device *dev, · line 181
Quoted 10 lines
include/linux/gpio/consumer.h +10
-0+* can be sure that there is no optional GPIO and let gpiod_get_optional +* safely return NULL. +* Otherwise there is still a chance that there is no GPIO but we cannot +* be sure without having to enable a part of GPIOLIB (i.e. the lookup +* part). So lets play safe and return an error. (Though there are also +* arguments that returning NULL then would be beneficial.) +*/ + +if (IS_ENABLED (CONFIG_OF ) && dev && dev->of_node) +return false;At first sight, I though this was OK:
1. On ARM with DT, we can assume
CONFIG_GPIOLOB=y.2. I managed to configure an SH kernel with
CONFIG_GPIOLOB=n,CONFIG_OF=y, andCONFIG_SERIAL_SH_SCI=y, but since SH boards with SH-SCI UARTs do not use DT (yet), the check fordev->of_node(false) should handle that.Quoted 7 lines
Quoted 5 lines
3. However, I managed to do the same for h8300, which does use DT. Hence if
mctrl_gpiowould start relying ongpiod_get_optional(), this would break the sh-sci driver on h8300 :-(
Note that h8300 doesn't have any GPIO drivers (yet?), soCONFIG_GPIPOLIB=nmakes perfect sense!Thanks for your efforts.
You're welcome.
Quoted 3 lines
Quoted 2 lines
So I'm afraid the only option is to always return NULL, and put the responsability on the shoulders of the system integrator...
Quoted 6 lines
Quoted 3 lines
The gpio lines could be provided by an i2c gpio adapter, right? So IMHO you don't need platform gpios to justify
-ENODEV. So I guess that's a case where we don't come to an agreement.While you can enable I2C without further dependencies, no I2C GPIO expander will be offered... unless you have enabled
CONFIG_GPIOLIBfirst.
And that is expected, still the device tree could reference such a GPIO and thus create a situation where Dmitry's and my judgement disagree.
So I think my suggestion is the best we could do now. It minimizes the number of cases where we disagree. The next best thing would be to implement that half gpiolib stuff (i.e. do the full lookup to be sure there is no gpio) but this comes at a price: We need some time to implement it and it adds a bit to the kernel size.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
Hi Uwe,
Quoted 84 lines · Uwe Kleine-K?nig
Quoted 83 lines · Geert Uytterhoeven
Quoted 64 lines · Uwe Kleine-K?nig
Quoted 63 lines · Geert Uytterhoeven
Quoted 41 lines · Uwe Kleine-K?nig
From: Uwe Kleine-K?nig <[email protected]>
Subject: [PATCH] gpiod: letget_optionalreturn NULL in some cases with GPIOLIB disabledPeople disagree if
gpiod_get_optionalshould return NULL orERR_PTR(-ENOSYS)if GPIOLIB is disabled. The argument for NULL is that the person who decided to disable GPIOLIB is assumed to know that there is no GPIO. The reason to stick toERR_PTR(-ENOSYS)is that it might introduce hard to debug problems if that decision is wrong.So this patch introduces a compromise and let
gpiod_get_optional(and its variants) return NULL if the device in question cannot have an associated GPIO because it is neither instantiated by a device tree nor by ACPI.This should handle most cases that are argued about.
Signed-off-by Uwe Kleine-K?nig <[email protected]>--- include/linux/gpio/consumer.h | 55 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 9 deletions(-)include/linux/gpio/consumer.h +7
-4@@ -161,20 +161,48 @@ gpiod_get_index(struct device *dev,return ERR_PTR (-ENOSYS ); } -static inline struct gpio_desc *__must_check -gpiod_get_optional (struct device *dev,const char *con_id, -enum gpiod_flags flags) +static inline bool __gpiod_no_optional_possible (struct device *dev) { -return ERR_PTR (-ENOSYS ); +/* +* gpiod_get_optional et al can only provide a GPIO if at least one of +* the backends for specifing a GPIO is available. These are device +* tree, ACPI and gpiolib's lookup tables. The latter isn't available if +* GPIOLIB is disabled (which is the case here). +* So if the provided device is unrelated to device tree and ACPI, we include/linux/gpio/consumer.h gpiod_get_index(struct device *dev, · line 181
Quoted 10 lines
include/linux/gpio/consumer.h +10
-0+* can be sure that there is no optional GPIO and let gpiod_get_optional +* safely return NULL. +* Otherwise there is still a chance that there is no GPIO but we cannot +* be sure without having to enable a part of GPIOLIB (i.e. the lookup +* part). So lets play safe and return an error. (Though there are also +* arguments that returning NULL then would be beneficial.) +*/ + +if (IS_ENABLED (CONFIG_OF ) && dev && dev->of_node) +return false;At first sight, I though this was OK:
1. On ARM with DT, we can assume
CONFIG_GPIOLOB=y.2. I managed to configure an SH kernel with
CONFIG_GPIOLOB=n,CONFIG_OF=y, andCONFIG_SERIAL_SH_SCI=y, but since SH boards with SH-SCI UARTs do not use DT (yet), the check fordev->of_node(false) should handle that.Quoted 7 lines
Quoted 5 lines
3. However, I managed to do the same for h8300, which does use DT. Hence if
mctrl_gpiowould start relying ongpiod_get_optional(), this would break the sh-sci driver on h8300 :-(
Note that h8300 doesn't have any GPIO drivers (yet?), soCONFIG_GPIPOLIB=nmakes perfect sense!Thanks for your efforts.
You're welcome.
Quoted 6 lines
Quoted 2 lines
So I'm afraid the only option is to always return NULL, and put the responsability on the shoulders of the system integrator...
The gpio lines could be provided by an i2c gpio adapter, right? So IMHO you don't need platform gpios to justify
-ENODEV. So I guess that's a case where we don't come to an agreement.
Quoted 5 lines
Quoted 2 lines
While you can enable I2C without further dependencies, no I2C GPIO expander will be offered... unless you have enabled
CONFIG_GPIOLIBfirst.And that is expected, still the device tree could reference such a GPIO and thus create a situation where Dmitry's and my judgement disagree.
If the device tree references such a GPIO, and CONFIG_GPIOLIB is not set, the I2C GPIO expander device will not be bound.
Frank Rowand's DT scripts (http://elinux.org/Device_Tree_frowand) will come to the rescue, and inform the user which driver(s) to enable.
Quoted 5 lines
So I think my suggestion is the best we could do now. It minimizes the number of cases where we disagree. The next best thing would be to implement that half gpiolib stuff (i.e. do the full lookup to be sure there is no gpio) but this comes at a price: We need some time to implement it and it adds a bit to the kernel size.
So I still have to handle -ENOSYS in sh-sci.c, to avoid regressions...
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Hello Geert,
Quoted 93 lines · Geert Uytterhoeven
Quoted 80 lines · Uwe Kleine-K?nig
Quoted 79 lines · Geert Uytterhoeven
Quoted 76 lines · Uwe Kleine-K?nig
Quoted 63 lines · Geert Uytterhoeven
Quoted 41 lines · Uwe Kleine-K?nig
From: Uwe Kleine-K?nig <[email protected]>
Subject: [PATCH] gpiod: letget_optionalreturn NULL in some cases with GPIOLIB disabledPeople disagree if
gpiod_get_optionalshould return NULL orERR_PTR(-ENOSYS)if GPIOLIB is disabled. The argument for NULL is that the person who decided to disable GPIOLIB is assumed to know that there is no GPIO. The reason to stick toERR_PTR(-ENOSYS)is that it might introduce hard to debug problems if that decision is wrong.So this patch introduces a compromise and let
gpiod_get_optional(and its variants) return NULL if the device in question cannot have an associated GPIO because it is neither instantiated by a device tree nor by ACPI.This should handle most cases that are argued about.
Signed-off-by Uwe Kleine-K?nig <[email protected]>--- include/linux/gpio/consumer.h | 55 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 9 deletions(-)include/linux/gpio/consumer.h +7
-4@@ -161,20 +161,48 @@ gpiod_get_index(struct device *dev,return ERR_PTR (-ENOSYS ); } -static inline struct gpio_desc *__must_check -gpiod_get_optional (struct device *dev,const char *con_id, -enum gpiod_flags flags) +static inline bool __gpiod_no_optional_possible (struct device *dev) { -return ERR_PTR (-ENOSYS ); +/* +* gpiod_get_optional et al can only provide a GPIO if at least one of +* the backends for specifing a GPIO is available. These are device +* tree, ACPI and gpiolib's lookup tables. The latter isn't available if +* GPIOLIB is disabled (which is the case here). +* So if the provided device is unrelated to device tree and ACPI, we include/linux/gpio/consumer.h gpiod_get_index(struct device *dev, · line 181
Quoted 10 lines
include/linux/gpio/consumer.h +10
-0+* can be sure that there is no optional GPIO and let gpiod_get_optional +* safely return NULL. +* Otherwise there is still a chance that there is no GPIO but we cannot +* be sure without having to enable a part of GPIOLIB (i.e. the lookup +* part). So lets play safe and return an error. (Though there are also +* arguments that returning NULL then would be beneficial.) +*/ + +if (IS_ENABLED (CONFIG_OF ) && dev && dev->of_node) +return false;At first sight, I though this was OK:
1. On ARM with DT, we can assume
CONFIG_GPIOLOB=y.2. I managed to configure an SH kernel with
CONFIG_GPIOLOB=n,CONFIG_OF=y, andCONFIG_SERIAL_SH_SCI=y, but since SH boards with SH-SCI UARTs do not use DT (yet), the check fordev->of_node(false) should handle that.Quoted 8 lines
3. However, I managed to do the same for h8300, which does use DT. Hence if
mctrl_gpiowould start relying ongpiod_get_optional(), this would break the sh-sci driver on h8300 :-(
Note that h8300 doesn't have any GPIO drivers (yet?), soCONFIG_GPIPOLIB=nmakes perfect sense!So I'm afraid the only option is to always return NULL, and put the responsability on the shoulders of the system integrator...
The gpio lines could be provided by an i2c gpio adapter, right? So IMHO you don't need platform gpios to justify
-ENODEV. So I guess that's a case where we don't come to an agreement.Quoted 5 lines
Quoted 2 lines
While you can enable I2C without further dependencies, no I2C GPIO expander will be offered... unless you have enabled
CONFIG_GPIOLIBfirst.And that is expected, still the device tree could reference such a GPIO and thus create a situation where Dmitry's and my judgement disagree.
If the device tree references such a GPIO, and
CONFIG_GPIOLIBis not set, the I2C GPIO expander device will not be bound.
Frank Rowand's DT scripts (http://elinux.org/Device_Tree_frowand) will come to the rescue, and inform the user which driver(s) to enable.
Quoted 7 lines
Quoted 5 lines
So I think my suggestion is the best we could do now. It minimizes the number of cases where we disagree. The next best thing would be to implement that half gpiolib stuff (i.e. do the full lookup to be sure there is no gpio) but this comes at a price: We need some time to implement it and it adds a bit to the kernel size.
So I still have to handle
-ENOSYSinsh-sci.c, to avoid regressions...
How much would it hurt to enable GPIOLIB there now? I assume that the platform has GPIOs and it's only an intermediate step that there is no driver for it at present? At some point you have to bite the bullet. Given that mctrl_gpio is a usage of GPIOs that might be now?
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
Quoted 26 lines · Uwe Kleine-K?nig
Quoted 17 lines · Dmitry Torokhov
Quoted 16 lines · Dmitry Torokhov
Quoted 15 lines · Linus Walleij
Quoted 11 lines · Uwe Kleine-K?nig
Maybe we can make
gpiod_get_optionallook like this:if (!dev->of_node && isnt_a_acpi_device(dev) && !IS_ENABLED(GPIOLIB)) return NULL; else return -ENOSYS;I don't know how
isnt_a_acpi_devicelooks like, probably it involvesCONFIG_ACPIand/ordev->acpi_node.This should be safe and still comfortable for legacy platforms, isn't it?
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
I like the looks of this.
Can we revert Dmitry's patch and apply something like this instead?
Dmitry, how do you feel about this?
I frankly do not see the point. It still makes driver code more complex
Quoted 8 lines
Note that this code is in the gpio header, and not in driver code. So the driver just does
gpiod = gpiod_get_optional(...) if (IS_ERR(gpiod)) return PTR_ERR(gpiod);(as it is supposed to do now). I think that's nice.
It does look nice. Compare this to what we must do for optional regulators:
st->reg = devm_regulator_get_optional(&spi->dev, "vref");
if (IS_ERR(st->reg)) {
/* Any other error indicates that the regulator does exist */
if (PTR_ERR(st->reg) != -ENODEV)
return PTR_ERR(st->reg);
/* Use internal reference */
}So for optional regulators we get -ENODEV if we don't have it, and then proceed on an alternate path, such as using an internal reference voltage.
However the fact that regulators and GPIO optionals are already handled differently is creating "cognitive dissonance" or what I should call it.
Yours,
Linus Walleij
Quoted 6 lines · Uwe Kleine-K?nig
Hello,
Quoted 2 lines · Geert Uytterhoeven
But having the error breaks setups where the GPIO is optional and does not exist.
Quoted 6 lines
so the right way forward is to check harder in the situation where
-ENOSYSwas returned before to determine if there is really no GPIO to be used. "Oh, there are hints that there is no GPIO (GPIOLIB=n), so lets assume there isn't." is wrong.Can we please properly fix the problem instead of papering over it?
I think I once already said what would need to _attempt_ to fix it "properly". You would need to implement custom parsing of ACPI tables in GPIOLIB (what if they disable ACPI by mistake?), do the same for OF, call board's manufacturer hotline to ensure that they indeed did not forget to describe GPIOs, etc, etc.
Or you could trust that person responsible for selecting kernel configuration has a clue, and if GPIOLIB is disabled it was disabled for a reason.
Signature · 1 line
Dmitry
Quoted 3 lines · Uwe Kleine-K?nig
So you exchanged many obvious and easy to fix problems with a few hard ones. I don't agree that's a good idea, but you seem to be willing to try it. Good luck.
I think instead of going to sarcastic remarks you can say you NACK the patch and suggest that it be reverted?
The problem I have here as maintainer is that both you and Dmitry are very smart people and I have a great deal of trust invested in both of you.
When two valued contributors give me very different advice I get a bit confused and maybe the best option is not to change anything at all right now, and just revert Dmitry's patch.
git grep -e 'gpio.*optional(' | wc -l
gives 154 use sites outside drivers/gpio, so it is not impossible to fix this if we want a good and strict order to it. I'm just a bit overworked to do it myself right now.
What do you all say, is it better to revert Dmitry's patch and instead go around and fix the consumers to do it correctly everywhere, after hammering down the exact semantics?
Yours,
Linus Walleij