[4/4] tty/serial: sh-sci: remove uneeded IS_ERR_OR_NULL calls

Submitted by Linus Walleij on March 16, 2017, 3:18 p.m.

Details

Message ID CACRpkdYeFyr4yjQjDAUpPJwuD_NW2y=wXnzt1xSNoOX0SFCLmw@mail.gmail.com
State New
Headers show

Commit Message

Linus Walleij March 16, 2017, 3:18 p.m.
On Mon, Mar 6, 2017 at 11:02 AM, Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
> On Mon, Mar 06, 2017 at 10:53:27AM +0100, Geert Uytterhoeven wrote:
>> On Mon, Mar 6, 2017 at 10:30 AM, Uwe Kleine-König

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

> 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?

From 2ecc70acc510784d953add707f2a5acfebe484c2 Mon Sep 17 00:00:00 2001
From: Linus Walleij <linus.walleij@linaro.org>
Date: Thu, 16 Mar 2017 16:18:21 +0100
Subject: [PATCH] stab at mctrl

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/tty/serial/Kconfig             |  1 +
 drivers/tty/serial/serial_mctrl_gpio.h | 55 ----------------------------------
 2 files changed, 1 insertion(+), 55 deletions(-)

 #endif

Comments

Uwe Kleine-König March 16, 2017, 4:37 p.m.
On Thu, Mar 16, 2017 at 04:18:52PM +0100, Linus Walleij wrote:
> On Mon, Mar 6, 2017 at 11:02 AM, Uwe Kleine-König
> <u.kleine-koenig@pengutronix.de> wrote:
> > On Mon, Mar 06, 2017 at 10:53:27AM +0100, Geert Uytterhoeven wrote:
> >> On Mon, Mar 6, 2017 at 10:30 AM, Uwe Kleine-König
> 
> >> > 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.
> >>
> >> 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.
> >
> >> 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:
> 
> > 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?

Would be ok for me, too. People seem to object to that though.

Best regards
Uwe
Geert Uytterhoeven March 16, 2017, 4:38 p.m.
Hi Linus,

On Thu, Mar 16, 2017 at 4:18 PM, Linus Walleij <linus.walleij@linaro.org> wrote:
> On Mon, Mar 6, 2017 at 11:02 AM, Uwe Kleine-König
> <u.kleine-koenig@pengutronix.de> wrote:
>> On Mon, Mar 06, 2017 at 10:53:27AM +0100, Geert Uytterhoeven wrote:
>>> On Mon, Mar 6, 2017 at 10:30 AM, Uwe Kleine-König
>>> > 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.
>>>
>>> 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.
>>
>>> 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:
>
>> 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?

It's not that black-and-white. Some of SuperH have GPIOLIB, other parts don't.

> 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?

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@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
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Geert Uytterhoeven March 20, 2017, 9:56 a.m.
Hi Linus,

On Thu, Mar 16, 2017 at 5:38 PM, Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
>> 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?
>
> 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.

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@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
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Geert Uytterhoeven March 20, 2017, 10:03 a.m.
On Mon, Mar 20, 2017 at 10:56 AM, Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
> drivers/tty/serial/serial_mctrl_gpio.o already compiles fine if
> CONFIG_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@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
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Uwe Kleine-König March 20, 2017, 10:31 a.m.
Hello Geert,

On Mon, Mar 20, 2017 at 10:56:14AM +0100, Geert Uytterhoeven wrote:
> 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.

I cannot find this paragraph in Documentation/gpio/consumer.txt:

	$ git grep -e 'ENOSYS' v4.11-rc3 -- Documentation/gpio/
	<void>

Best regards
Uwe
Geert Uytterhoeven March 20, 2017, 10:38 a.m.
Hi Uwe,

On Mon, Mar 20, 2017 at 11:31 AM, Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
> On Mon, Mar 20, 2017 at 10:56:14AM +0100, Geert Uytterhoeven wrote:
>> 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.
>
> 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@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
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Uwe Kleine-König March 20, 2017, 11:07 a.m.
Hello Geert,

On Mon, Mar 20, 2017 at 11:38:52AM +0100, Geert Uytterhoeven wrote:
> On Mon, Mar 20, 2017 at 11:31 AM, Uwe Kleine-König
> <u.kleine-koenig@pengutronix.de> wrote:
> > On Mon, Mar 20, 2017 at 10:56:14AM +0100, Geert Uytterhoeven wrote:
> >> 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.
> >
> > 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")

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
Linus Walleij March 23, 2017, 9:32 a.m.
On Mon, Mar 20, 2017 at 12:07 PM, Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
> Hello Geert,
>
> On Mon, Mar 20, 2017 at 11:38:52AM +0100, Geert Uytterhoeven wrote:
>> On Mon, Mar 20, 2017 at 11:31 AM, Uwe Kleine-König
>> <u.kleine-koenig@pengutronix.de> wrote:
>> > On Mon, Mar 20, 2017 at 10:56:14AM +0100, Geert Uytterhoeven wrote:
>> >> 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.
>> >
>> > 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")
>
> 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
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Uwe Kleine-König March 23, 2017, 10:10 a.m.
On Thu, Mar 23, 2017 at 10:32:01AM +0100, Linus Walleij wrote:
> On Mon, Mar 20, 2017 at 12:07 PM, Uwe Kleine-König
> <u.kleine-koenig@pengutronix.de> wrote:
> > Hello Geert,
> >
> > On Mon, Mar 20, 2017 at 11:38:52AM +0100, Geert Uytterhoeven wrote:
> >> On Mon, Mar 20, 2017 at 11:31 AM, Uwe Kleine-König
> >> <u.kleine-koenig@pengutronix.de> wrote:
> >> > On Mon, Mar 20, 2017 at 10:56:14AM +0100, Geert Uytterhoeven wrote:
> >> >> 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.
> >> >
> >> > 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")
> >
> > 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.

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.
 
> 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
Geert Uytterhoeven March 23, 2017, 10:20 a.m.
Hi Uwe,

On Thu, Mar 23, 2017 at 11:10 AM, Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
> On Thu, Mar 23, 2017 at 10:32:01AM +0100, Linus Walleij wrote:
>> On Mon, Mar 20, 2017 at 12:07 PM, Uwe Kleine-König
>> <u.kleine-koenig@pengutronix.de> wrote:
>> > On Mon, Mar 20, 2017 at 11:38:52AM +0100, Geert Uytterhoeven wrote:
>> >> On Mon, Mar 20, 2017 at 11:31 AM, Uwe Kleine-König
>> >> <u.kleine-koenig@pengutronix.de> wrote:
>> >> > On Mon, Mar 20, 2017 at 10:56:14AM +0100, Geert Uytterhoeven wrote:
>> >> >> 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.
>> >> >
>> >> > 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")
>> >
>> > 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.
>
> 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.
>
>> 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.

If I forget to enable a driver, the corresponding class device is also not
there.

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

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

> 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@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
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Uwe Kleine-König March 23, 2017, 11:11 a.m.
Hello,

On Thu, Mar 23, 2017 at 11:20:39AM +0100, Geert Uytterhoeven wrote:
> 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?

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

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

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

Doing things right is sometimes not maximally easy. But that is no
excuse to do it wrong.

Best regards
Uwe
Geert Uytterhoeven March 23, 2017, 12:03 p.m.
Hi Uwe,

On Thu, Mar 23, 2017 at 12:11 PM, Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
>> 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.)
>
>> > 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.

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@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
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Uwe Kleine-König March 23, 2017, 12:34 p.m.
On Thu, Mar 23, 2017 at 01:03:56PM +0100, Geert Uytterhoeven wrote:
> Hi Uwe,
> 
> On Thu, Mar 23, 2017 at 12:11 PM, Uwe Kleine-König
> <u.kleine-koenig@pengutronix.de> wrote:
> >> 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.)
> >
> >> > 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.
> 
> 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?

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
Geert Uytterhoeven March 23, 2017, 12:44 p.m.
Hi Uwe,

On Thu, Mar 23, 2017 at 1:34 PM, Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
> On Thu, Mar 23, 2017 at 01:03:56PM +0100, Geert Uytterhoeven wrote:
>> On Thu, Mar 23, 2017 at 12:11 PM, Uwe Kleine-König
>> <u.kleine-koenig@pengutronix.de> wrote:
>> >> 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.)
>> >
>> >> > 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.
>>
>> 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?
>
> 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?

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@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
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij March 23, 2017, 1:37 p.m.
On Thu, Mar 23, 2017 at 11:10 AM, Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:

> 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
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij March 23, 2017, 1:41 p.m.
On Thu, Mar 23, 2017 at 1:34 PM, Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:

> 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?

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
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dmitry Torokhov March 23, 2017, 2:43 p.m.
On Thu, Mar 23, 2017 at 02:41:53PM +0100, Linus Walleij wrote:
> On Thu, Mar 23, 2017 at 1:34 PM, Uwe Kleine-König
> <u.kleine-koenig@pengutronix.de> wrote:
> 
> > 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?
> 
> 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.
Dmitry Torokhov March 23, 2017, 3:44 p.m.
On Thu, Mar 23, 2017 at 07:43:25AM -0700, Dmitry Torokhov wrote:
> On Thu, Mar 23, 2017 at 02:41:53PM +0100, Linus Walleij wrote:
> > On Thu, Mar 23, 2017 at 1:34 PM, Uwe Kleine-König
> > <u.kleine-koenig@pengutronix.de> wrote:
> > 
> > > 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?
> > 
> > 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.

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.
Dmitry Torokhov March 23, 2017, 3:55 p.m.
On Thu, Mar 23, 2017 at 12:11:06PM +0100, Uwe Kleine-König wrote:
> Hello,
> 
> On Thu, Mar 23, 2017 at 11:20:39AM +0100, Geert Uytterhoeven wrote:
> > 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?

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.
Uwe Kleine-König March 23, 2017, 7:10 p.m.
On Thu, Mar 23, 2017 at 08:44:41AM -0700, Dmitry Torokhov wrote:
> On Thu, Mar 23, 2017 at 07:43:25AM -0700, Dmitry Torokhov wrote:
> > On Thu, Mar 23, 2017 at 02:41:53PM +0100, Linus Walleij wrote:
> > > On Thu, Mar 23, 2017 at 1:34 PM, Uwe Kleine-König
> > > <u.kleine-koenig@pengutronix.de> wrote:
> > > 
> > > > 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?
> > > 
> > > 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.

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

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

> > 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 */

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
Dmitry Torokhov March 23, 2017, 7:58 p.m.
On Thu, Mar 23, 2017 at 08:10:20PM +0100, Uwe Kleine-König wrote:
> On Thu, Mar 23, 2017 at 08:44:41AM -0700, Dmitry Torokhov wrote:
> > On Thu, Mar 23, 2017 at 07:43:25AM -0700, Dmitry Torokhov wrote:
> > > On Thu, Mar 23, 2017 at 02:41:53PM +0100, Linus Walleij wrote:
> > > > On Thu, Mar 23, 2017 at 1:34 PM, Uwe Kleine-König
> > > > <u.kleine-koenig@pengutronix.de> wrote:
> > > > 
> > > > > 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?
> > > > 
> > > > 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.

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.

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

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

> 
> > > 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 */
> 
> 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.
Linus Walleij March 24, 2017, 8:58 a.m.
On Thu, Mar 23, 2017 at 8:10 PM, Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
> On Thu, Mar 23, 2017 at 08:44:41AM -0700, Dmitry Torokhov wrote:
>> On Thu, Mar 23, 2017 at 07:43:25AM -0700, Dmitry Torokhov wrote:
>> > On Thu, Mar 23, 2017 at 02:41:53PM +0100, Linus Walleij wrote:
>> > > On Thu, Mar 23, 2017 at 1:34 PM, Uwe Kleine-König
>> > > <u.kleine-koenig@pengutronix.de> wrote:
>> > >
>> > > > 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?
>> > >
>> > > 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.

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
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch hide | download patch | download mbox

diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
index 6117ac8da48f..39833d009c18 100644
--- a/drivers/tty/serial/Kconfig
+++ b/drivers/tty/serial/Kconfig
@@ -1681,5 +1681,6 @@  endmenu

 config SERIAL_MCTRL_GPIO
     tristate
+    depends on GPIOLIB

 endif # TTY
diff --git a/drivers/tty/serial/serial_mctrl_gpio.h
b/drivers/tty/serial/serial_mctrl_gpio.h
index fa000bcff217..ba8f8e531d56 100644
--- a/drivers/tty/serial/serial_mctrl_gpio.h
+++ b/drivers/tty/serial/serial_mctrl_gpio.h
@@ -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 */
-