From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
Linus Walleij <linus.walleij@linaro.org>,
Florian Fainelli <florian.fainelli@broadcom.com>,
Mark Brown <broonie@kernel.org>
Subject: Re: [PATCH v1 1/1] gpiolib: Make gpiod_put() error pointer aware
Date: Thu, 3 Apr 2025 14:16:55 +0300 [thread overview]
Message-ID: <Z-5uJxij4jmhint3@smile.fi.intel.com> (raw)
In-Reply-To: <CAMRc=Mc12B-b-w6bJeOgwFvzbmaqzL+uT7vJssVYN4tMu3YpaQ@mail.gmail.com>
On Thu, Apr 03, 2025 at 10:20:08AM +0200, Bartosz Golaszewski wrote:
> On Thu, Apr 3, 2025 at 10:04 AM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > On Thu, Apr 03, 2025 at 08:58:09AM +0200, Bartosz Golaszewski wrote:
> > > On Wed, Apr 2, 2025 at 5:20 PM Andy Shevchenko
> > > <andriy.shevchenko@linux.intel.com> wrote:
> > > > When non-optional GPIO is requested and failed, the variable that holds
> > > > the (invalid) descriptor can contain an error pointer. However, gpiod_put()
> > > > ignores that fact and tries to cleanup never requested descriptor.
> > > > Make sure gpiod_put() ignores that as well.
> > > >
> > > > While at it, do the same for the gpiod_put_array().
> > > >
> > > > Note, it arguable needs to be present in the stubs as those are usually
> > > > called when CONFIG_GPIOLIB=n and GPIOs are requested using gpiod_get_optional()
> > > > or similar APIs.
> >
> > > I'm not a fan of this. Silently ignoring NULL makes sense in the
> > > context of _optional() calls where we want to do nothing on GPIOs that
> > > aren't there.
> >
> > > But this encourages people to get sloppy and just ignore
> > > error pointers returned from gpiod_get()?
> >
> > From where did you come to this conclusion, please? We have many subsystems
> > that ignore invalid resource on the release stage, starting from platform
> > device driver core.
>
> The fact that many people do something does not mean it's correct.
And it doesn't tell it is incorrect either. We are going to conclude that there
are pros and cons on each of the approaches, but I don't see much a point in
yours, sorry.
> Many other subsystem scream loudly when that happens, so I would be ok
> with adding a big WARN_ON(IS_ERR(desc)).
I disagree. This is not that case where passing an error pointer should be
an issue.
> > > Also: all other calls error out on IS_ERR(desc) so why would we make it an
> > > exception?
> >
> > Because it's _release_ stage that participates in the cleaning up of
> > the allocated resources in error paths. It's a common approach in
> > the kernel. I would rather ask what makes GPIOLIB so special about it?
>
> Just because it's the release stage, does not mean you shouldn't care
> about the correctness of the consumer code. Passing an IS_ERR(descr)
> to any of the GPIO APIs can happen if the user ignores an error
> returned by gpiod_get(). That's not alright.
Have you ever seen such a code in the cases when it's okay (like in platform
device driver users)? I do not. So, the above is based on the hypothetical
assumption that somebody will make silly things. If you _really_ care about
checking the error, add __must_check to the respective functions.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2025-04-03 11:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-02 15:20 [PATCH v1 1/1] gpiolib: Make gpiod_put() error pointer aware Andy Shevchenko
2025-04-03 6:58 ` Bartosz Golaszewski
2025-04-03 8:04 ` Andy Shevchenko
2025-04-03 8:20 ` Bartosz Golaszewski
2025-04-03 11:16 ` Andy Shevchenko [this message]
2025-04-03 12:23 ` Bartosz Golaszewski
2025-04-03 13:22 ` Andy Shevchenko
2025-04-07 12:49 ` Bartosz Golaszewski
2025-04-07 13:45 ` Andy Shevchenko
2025-04-15 9:32 ` Linus Walleij
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=Z-5uJxij4jmhint3@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=bartosz.golaszewski@linaro.org \
--cc=brgl@bgdev.pl \
--cc=broonie@kernel.org \
--cc=florian.fainelli@broadcom.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).