lkml.org 
[lkml]   [2022]   [Mar]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] gpiolib: fix the size of the ngpios variable
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

\
 
 \ /
  Last update: 2022-03-06 20:23    [W:0.054 / U:2.276 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site