Re: [PATCH][next] gpio: xilinx: Fix potential integer overflow on shift of a u32 int

From: Andy Shevchenko
Date: Mon May 17 2021 - 03:05:22 EST


On Thu, May 13, 2021 at 1:04 PM David Laight <David.Laight@xxxxxxxxxx> wrote:
> > From: Colin Ian King <colin.king@xxxxxxxxxxxxx>

> > @@ -99,7 +99,7 @@ static inline void xgpio_set_value32(unsigned long *map, int bit, u32 v)
> > const unsigned long offset = (bit % BITS_PER_LONG) & BIT(5);
> >
> > map[index] &= ~(0xFFFFFFFFul << offset);
> > - map[index] |= v << offset;
> > + map[index] |= (unsigned long)v << offset;
> > }
>
> That code looks dubious on 32bit architectures.
>
> I don't have 02b3f84d9080 in any of my source trees.

Can you please be more specific on which code is dubious on 32-bit
arches and why?

> But that patch may itself be very dubious.
>
> Since the hardware requires explicit bits be set, relying
> on the bitmap functions seems pointless and possibly wrong.
> Clearly they cause additional problems because they use long[]
> and here the code needs u32[].

--
With Best Regards,
Andy Shevchenko