[PATCH 5.10] gpiolib: acpi: handle overflow check in acpi_gpio_adr_space_handler()

From: Alexandr Sapozhnikov

Date: Mon Nov 10 2025 - 10:32:56 EST


Added an overflow check when setting a bit, since the function will not work
correctly if there is an overflow.

Found by Linux Verification Center (linuxtesting.org) with svace.

Fixes: dc62b56a68d3 ("gpio / ACPI: use *_cansleep version of gpiod_get/set APIs")
Signed-off-by: Alexandr Sapozhnikov <alsp705@xxxxxxxxx>
---
drivers/gpio/gpiolib-acpi.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index 834a12f3219e..dfb421bff979 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -1069,6 +1069,11 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,

mutex_unlock(&achip->conn_lock);

+ if (i < 0 || i > 64) {
+ status=-EINVAL;
+ goto out;
+ }
+
if (function == ACPI_WRITE)
gpiod_set_raw_value_cansleep(desc,
!!((1 << i) & *value));
--
2.51.0