Skip to contentSkip to conversation

gpio: gpio-xilinx: Fix integer overflow

PATCH Applied Srinivas Neeli 3 participants 5 messages Jul 21, 2022 – Jul 25, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: gpio-xilinx: Fix integer overflow

Current implementation is not able to configure more than 32 pins due to incorrect data type. So type casting with unsigned long to avoid it.

Fixes 02b3f84d9080 ("xilinx: Switch to use bitmap APIs")
---
 drivers/gpio/gpio-xilinx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-xilinx.c +1 -1
index b6d3a57e27ed..7f8e2fed2988 100644
@@ -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;
 }
 
 static inline int xgpio_regoffset(struct xgpio_instance *chip, int ch)
Signature · 1 line
2.17.1
#1 lore raw
Quoted 25 lines · Srinivas Neeli

Current implementation is not able to configure more than 32 pins due to incorrect data type. So type casting with unsigned long to avoid it.

Fixes 02b3f84d9080 ("xilinx: Switch to use bitmap APIs")
---
 drivers/gpio/gpio-xilinx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-xilinx.c +1 -2
index b6d3a57e27ed..7f8e2fed2988 100644
@@ -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;
 }
 
 static inline int xgpio_regoffset(struct xgpio_instance *chip, int ch)
--
Quoted 2 lines

2.17.1

Applied, thanks!

Bart

#2 lore raw
Quoted 8 lines · Bartosz Golaszewski
Quoted 6 lines · Srinivas Neeli

Current implementation is not able to configure more than 32 pins due to incorrect data type. So type casting with unsigned long to avoid it.

Fixes 02b3f84d9080 ("xilinx: Switch to use bitmap APIs")

It doesn't fix anything, I already reject one such "fix" during development of this patch. Thanks!

...

Quoted 9 lines

drivers/gpio/gpio-xilinx.c static inline void xgpio_set_value32(unsigned long *map, int bit, u32 v) · line 103

Quoted 7 lines
drivers/gpio/gpio-xilinx.c +1 -1
@@ -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;
 }

Applied, thanks!

False positive.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Bartosz Golaszewski
Quoted 1 line · Srinivas Neeli
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

Current implementation is not able to configure more than 32 pins due to incorrect data type. So type casting with unsigned long to avoid it.

Fixes 02b3f84d9080 ("xilinx: Switch to use bitmap APIs")

It doesn't fix anything, I already reject one such "fix" during development of this patch. Thanks!

Sorry, not my day, it was something else that time... See below.

Quoted 7 lines

...

Quoted 3 lines

Review c

Quoted 1 line
(quoted diff) +0 -0
@@ -99,7 +99,7 @@ c

Applied, thanks!

False positive.

Reading again... You mean that

  unsigned long x = y << 32;

wouldn't work?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by
#4 lore raw
Quoted 5 lines · Andy Shevchenko
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Bartosz Golaszewski

On Thu, Jul 21, 2022 at 9:39 AM Srinivas Neeli
<[email protected]> wrote:

...

Quoted 5 lines

Reading again... You mean that

  unsigned long x = y << 32;

wouldn't work?

Yeah, I even checked this in asm, and indeed it doesn't work. Don't know what was that about me...

Thanks for the fix,

Signature · 2 lines
With Best Regards,
Andy Shevchenko