linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] gpiolib: fix the size of the ngpios variable
Date: Sun, 6 Mar 2022 20:22:16 +0100	[thread overview]
Message-ID: <CAMRc=Md011QRB1z0h=ktYwxKJbH1EQhvZWLnNzU1bhpXuo9sqA@mail.gmail.com> (raw)
In-Reply-To: <CAHp75VefVkNfGoFKtG3-3fF4TEiu33u-EaASEiTUmj_OAm-onA@mail.gmail.com>

On Sat, Mar 5, 2022 at 10:27 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Sat, Mar 5, 2022 at 10:14 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> >
> > The ngpio fields both in struct gpio_device as well as gpio_chip are
> > 16 bit unsigned integers. Let's not risk an overflow and use the correct
> > size when reading the device property.
>
> ...
>
> > -               ret = device_property_read_u32(&gdev->dev, "ngpios", &ngpios);
> > +               ret = device_property_read_u16(&gdev->dev, "ngpios", &ngpios);
>
> AFAIU DT format you may not do this. The property is ABI-like and it's
> 32-bit (BE!). Reading as u16 will bring you 2 MSB (bytes) out of 4
> from the 32-bit value.
>

Ah right. It's not very obvious from the docs but the DT syntax must
be different for 16 bits. In that case our best shot is to read a
32-bit unsigned integer and check if its value doesn't exceed
UINT16_MAX.

Bart

      reply	other threads:[~2022-03-06 19:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-05 15:42 [PATCH] gpiolib: fix the size of the ngpios variable Bartosz Golaszewski
2022-03-05 21:26 ` Andy Shevchenko
2022-03-06 19:22   ` Bartosz Golaszewski [this message]

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='CAMRc=Md011QRB1z0h=ktYwxKJbH1EQhvZWLnNzU1bhpXuo9sqA@mail.gmail.com' \
    --to=brgl@bgdev.pl \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy.shevchenko@gmail.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).