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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, May 17, 2021 at 10:03:15AM +0300, Andy Shevchenko wrote:
> On Thu, May 13, 2021 at 12:12 PM Colin King <colin.king@xxxxxxxxxxxxx> wrote:
> >
> > From: Colin Ian King <colin.king@xxxxxxxxxxxxx>
> >
> > The left shift of the u32 integer v is evaluated using 32 bit
> > arithmetic and then assigned to a u64 integer. There are cases
> > where v will currently overflow on the shift. Avoid this by
> > casting it to unsigned long (same type as map[]) before shifting
> > it.
> >
> > Addresses-Coverity: ("Unintentional integer overflow")
> > Fixes: 02b3f84d9080 ("gpio: xilinx: Switch to use bitmap APIs")
> 
> No, it is a false positive,
> 
> >         const unsigned long offset = (bit % BITS_PER_LONG) & BIT(5);
> 
> See above, offset is 0 when BITS_PER_LONG == 32 and 32 when it's equal to 64.

Should be read as "...and 0 or 32 when..."

> > -       map[index] |= v << offset;
> > +       map[index] |= (unsigned long)v << offset;

-- 
With Best Regards,
Andy Shevchenko





[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux