Skip to contentSkip to conversation

gpio / ACPI: Prevent potential wrap of GPIO value on OpRegion read

PATCH In review Mika Westerberg 2 participants 2 messages Apr 1, 2014 – Apr 10, 2014 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio / ACPI: Prevent potential wrap of GPIO value on OpRegion read

Dan Carpenter's static code checker reports:

The patch 473ed7be0da0: "gpio / ACPI: Add support for ACPI GPIO operation regions" from Mar 14, 2014, leads to the following static checker warning:

drivers/gpio/gpiolib-acpi.c:454 acpi_gpio_adr_space_handler()
warn: should 'gpiod_get_raw_value(desc) << i' be a 64 bit type?

This is due the fact that *value is of type u64 and gpiod_get_raw_value() returns int. Since i can be larger than 31, it is possible that the value returned gets wrapped.

Fix this by casting the return of gpiod_get_raw_value() to u64 first before shift.

---
 drivers/gpio/gpiolib-acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib-acpi.c +1 -1
index d5be56fe689e..401add28933f 100644
@@ -451,7 +451,7 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
 		if (function == ACPI_WRITE)
 			gpiod_set_raw_value(desc, !!((1 << i) & *value));
 		else
-			*value |= gpiod_get_raw_value(desc) << i;
+			*value |= (u64)gpiod_get_raw_value(desc) << i;
 	}
 
 out:
Signature · 1 line
1.9.1
#1 lore raw
Quoted 13 lines · Mika Westerberg

Dan Carpenter's static code checker reports:

The patch 473ed7be0da0: "gpio / ACPI: Add support for ACPI GPIO operation regions" from Mar 14, 2014, leads to the following static checker warning:

drivers/gpio/gpiolib-acpi.c:454 acpi_gpio_adr_space_handler()
warn: should 'gpiod_get_raw_value(desc) << i' be a 64 bit type?

This is due the fact that *value is of type u64 and gpiod_get_raw_value() returns int. Since i can be larger than 31, it is possible that the value returned gets wrapped.

Quoted 5 lines

Fix this by casting the return of gpiod_get_raw_value() to u64 first before shift.

Patch applied for fixes.

Yours,
Linus Walleij