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: Thu, 18 Nov 2021 23:16:27 +0200 [thread overview]
Message-ID: <YZbCq5Xcohm/t/FP@smile.fi.intel.com> (raw)
In-Reply-To: <CAMRc=MdR_RGLLPJ5Hqetj5_7ZQfUXOijEoVp3uR7cgEDHKnchA@mail.gmail.com>
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:
> > > Several drivers read the 'ngpios' device property on their own, but
> > > since it's defined as a standard GPIO property in the device tree bindings
> > > anyway, it's a good candidate for generalization. If the driver didn't
> > > set its gc->ngpio, try to read the 'ngpios' property from the GPIO
> > > device's firmware node before bailing out.
> >
> > ...
> >
> > > 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?
> > 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.
> > }
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2021-11-18 21:16 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 [this message]
2021-11-19 19:35 ` Bartosz Golaszewski
2021-11-22 11:20 ` Andy Shevchenko
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=YZbCq5Xcohm/t/FP@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;
as well as URLs for NNTP newsgroup(s).