From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Linus Walleij <linus.walleij@linaro.org>,
"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 2/2] gpiolib: check the 'ngpios' property in core gpiolib code
Date: Mon, 22 Nov 2021 13:20:45 +0200 [thread overview]
Message-ID: <YZt9DVihGaq0kjKG@smile.fi.intel.com> (raw)
In-Reply-To: <CAMRc=MdBhm-+oDiBdYQJZXYEko8rGhZtHQfu6p3DFy_a3aJOZw@mail.gmail.com>
On Fri, Nov 19, 2021 at 08:35:33PM +0100, Bartosz Golaszewski wrote:
> On Thu, Nov 18, 2021 at 10:16 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > On Thu, Nov 18, 2021 at 09:12:59PM +0100, Bartosz Golaszewski wrote:
> > > On Thu, Nov 18, 2021 at 6:06 PM Andy Shevchenko
> > > <andriy.shevchenko@linux.intel.com> wrote:
> > > > On Thu, Nov 18, 2021 at 02:23:17PM +0100, Bartosz Golaszewski wrote:
...
> > > > > if (gc->ngpio == 0) {
> > > > > - chip_err(gc, "tried to insert a GPIO chip with zero lines\n");
> > > > > - ret = -EINVAL;
> > > > > - goto err_free_descs;
> > > > > + ret = device_property_read_u32(&gdev->dev, "ngpios", &ngpios);
> > > > > + if (ret) {
> > > > > + chip_err(gc, "tried to insert a GPIO chip with zero lines\n");
> > > > > + ret = -EINVAL;
> > > > > + goto err_free_descs;
> > > > > + }
> > > > > +
> > > > > + gc->ngpio = ngpios;
> > > > > }
> > > >
> > > > This should be
> > > >
> > > > if (gc->ngpio == 0) {
> > > > ret = device_property_read_u32(&gdev->dev, "ngpios", &ngpios);
> > > > if (ret)
> > > > return ret;
> > >
> > > But device_property_read_u32() returning -ENODATA means there's no
> > > such property, which should actually be converted to -EINVAL as the
> > > caller wanting to create the chip provided invalid configuration - in
> > > this case: a chip with 0 lines. In case of the non-array variant of
> > > read_u32 that's also the only error that can be returned so this bit
> > > looks right to me.
> >
> > So, what is so special about -EINVAL? Why -ENODATA is not good enough which
> > will exactly explain to the caller what's going on, no?
> >
>
> Let's imagine the user sets gc->ngpio = 0 incorrectly thinking it'll
> make gpiolib set it to some sane default. Then gpiochip_add_data()
> returns -ENODATA (No data available). This is confusing IMO. But if we
> convert it to -EINVAL, it now says "Invalid value" which points to the
> wrong configuration.
>
> ENODATA means "device tree property is not present" in this case but
> the problem is that user supplies the gpiolib with invalid
> configuration. EINVAL is the right error here.
Then be explicit, don't shadow other error codes from fwnode API.
if (ret && ret != -ENODATA)
> > > > gc->ngpio = ngpios;
> > > > }
> > > >
> > > > if (gc->ngpio == 0) {
> > > > chip_err(gc, "tried to insert a GPIO chip with zero lines\n");
> > > > ret = -EINVAL;
> > > > goto err_free_descs;
> >
> > When the caller intended to create a chip with 0 GPIOs they will get an error
> > as you wish with an error message.
>
> Yes, as it was before.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2021-11-22 11:20 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-18 13:23 [PATCH v2 1/2] gpiolib: improve coding style for local variables Bartosz Golaszewski
2021-11-18 13:23 ` [PATCH v2 2/2] gpiolib: check the 'ngpios' property in core gpiolib code Bartosz Golaszewski
2021-11-18 15:44 ` Andy Shevchenko
2021-11-18 16:38 ` Bartosz Golaszewski
2021-11-18 17:01 ` Andy Shevchenko
2021-11-18 17:06 ` Andy Shevchenko
2021-11-18 17:05 ` Andy Shevchenko
2021-11-18 20:12 ` Bartosz Golaszewski
2021-11-18 21:16 ` Andy Shevchenko
2021-11-19 19:35 ` Bartosz Golaszewski
2021-11-22 11:20 ` Andy Shevchenko [this message]
2021-11-18 15:44 ` [PATCH v2 1/2] gpiolib: improve coding style for local variables Andy Shevchenko
2021-11-19 7:57 ` Johan Hovold
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=YZt9DVihGaq0kjKG@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=brgl@bgdev.pl \
--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