From: Andy Shevchenko <andy@kernel.org>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: "Kent Gibson" <warthog618@gmail.com>,
"Duje Mihanović" <duje.mihanovic@skole.hr>,
"Daniel Mack" <daniel@zonque.org>,
"Haojian Zhuang" <haojian.zhuang@gmail.com>,
"Robert Jarzmik" <robert.jarzmik@free.fr>,
"Russell King" <linux@armlinux.org.uk>,
"Alan Stern" <stern@rowland.harvard.edu>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Bartosz Golaszewski" <brgl@bgdev.pl>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
linux-gpio@vger.kernel.org
Subject: Re: [PATCH RFC 1/6] ARM: pxa: Convert Spitz OHCI to GPIO descriptors
Date: Sun, 1 Oct 2023 12:21:53 +0300 [thread overview]
Message-ID: <ZRk6MQllYmgxV0fu@smile.fi.intel.com> (raw)
In-Reply-To: <ZRkrYChL0hKZwQGp@smile.fi.intel.com>
On Sun, Oct 01, 2023 at 11:18:41AM +0300, Andy Shevchenko wrote:
> On Wed, Sep 27, 2023 at 04:01:58PM +0200, Linus Walleij wrote:
> > On Mon, Sep 25, 2023 at 9:30 AM Andy Shevchenko <andy@kernel.org> wrote:
...
> > > > + if (pxa_ohci->usb_host)
> > > > + gpiod_put(pxa_ohci->usb_host);
> > >
> > > Linus, Bart, do we have misdesigned _optinal() GPIO APIs?
> > >
> > > In GPIOLIB=n, the above requires that redundant check. Shouldn't we replace
> > > gpiod_put() stub to be simply no-op?
> >
> > You mean the WARN_ON(desc) in gpiod_put() in the static inline
> > stub version?
> >
> > I thought about it for a bit, drafted a patch removing them, and then
> > realized the following:
> >
> > If someone is making the gpiolib optional for a driver, i.e. neither
> > DEPENDS ON GPIOLIB nor SELECT GPIOLIB, they are a quite
> > narrow segment. I would say in 9 cases out of 10 or more this is
> > just a driver that should depend on or select GPIOLIB.
> >
> > I think such drivers should actually do the NULL checks and not be
> > too convenient, the reason is readability: someone reading that
> > driver will be thinking gpios are not optional if they can call
> > gpiod_set_value(), gpiod_put() etc without any sign that the
> > desc is optional.
> >
> > If the driver uses [devm_]gpiod_get_optional() the library is not
> > using the stubs and does the right thing, and it is clear that
> > the GPIO is *runtime* optional.
> >
> > But *compile time* optional, *combined* with runtime optional -
> > I'm not so happy if we try to avoid warnings around that. I think
> > it leads to confusing configs and code that looks like gpiolib is
> > around despite it wasn't selected.
> >
> > If the code isn't depending on or selecting GPIOLIB and still
> > use _optional() calls, it better be ready to do some extra checks,
> > because this is a weird combo, it can't be common.
> >
> > Could be a documentation update making this clear though.
> >
> > What do you other people think?
>
> The problem here indeed if the code is not selecting or being dependent on
> GPIOLIB and uses _optional() calls.
>
> I agree that this is quite a niche that should be addressed on the driver side.
One more thing, though. I think those warnings are incomplete or actually
reversed, and we outta use WARN_ON(IS_ERR(desc)), no?
This way it will fix my concerns and your concerns will be satisfied, right?
So, if gpiod_get() returns an error pointer and then we are trying to
free it with GPIOLIB=n, _then_ we will got a warning and it's obvious that
driver has to be prepared for that, otherwise if we have it NULL and
call for gpiod_get_optional(), even with GPIOLIB=n, it's fine to free, we
don't care.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2023-10-01 9:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-24 16:42 [PATCH RFC 0/6] ARM: pxa: GPIO descriptor conversions Duje Mihanović
2023-09-24 16:42 ` [PATCH RFC 1/6] ARM: pxa: Convert Spitz OHCI to GPIO descriptors Duje Mihanović
2023-09-25 7:30 ` Andy Shevchenko
2023-09-27 14:01 ` Linus Walleij
2023-10-01 8:18 ` Andy Shevchenko
2023-10-01 9:21 ` Andy Shevchenko [this message]
2023-10-02 8:00 ` Linus Walleij
2023-09-24 16:42 ` [PATCH RFC 2/6] ARM: pxa: Convert Spitz LEDs " Duje Mihanović
2023-09-24 16:42 ` [PATCH RFC 3/6] ARM: pxa: Convert Spitz CF power control " Duje Mihanović
2023-09-24 16:42 ` [PATCH RFC 4/6] ARM: pxa: Convert reset driver " Duje Mihanović
2023-09-25 7:34 ` Andy Shevchenko
2023-09-24 16:42 ` [PATCH RFC 5/6] ARM: pxa: Convert Spitz hsync " Duje Mihanović
2023-09-25 7:36 ` Andy Shevchenko
2023-09-25 15:07 ` Duje Mihanović
2023-09-24 16:42 ` [PATCH RFC 6/6] ARM: pxa: Convert gumstix Bluetooth " Duje Mihanović
2023-09-25 7:37 ` [PATCH RFC 0/6] ARM: pxa: GPIO descriptor conversions Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZRk6MQllYmgxV0fu@smile.fi.intel.com \
--to=andy@kernel.org \
--cc=brgl@bgdev.pl \
--cc=daniel@zonque.org \
--cc=duje.mihanovic@skole.hr \
--cc=gregkh@linuxfoundation.org \
--cc=haojian.zhuang@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=robert.jarzmik@free.fr \
--cc=stern@rowland.harvard.edu \
--cc=warthog618@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox