From: Denis Sergeev <denserg.edu@gmail.com>
To: westeri@kernel.org, andriy.shevchenko@linux.intel.com,
linusw@kernel.org, brgl@kernel.org
Cc: linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org,
linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org,
Denis Sergeev <denserg.edu@gmail.com>
Subject: [PATCH] gpiolib: acpi: use BIT_ULL() for u64 mask in address space handler
Date: Mon, 26 Jan 2026 06:59:14 +0300 [thread overview]
Message-ID: <20260126035914.16586-1-denserg.edu@gmail.com> (raw)
The BIT() macro uses unsigned long, which is 32 bits on 32-bit
architectures. When iterating over GPIO pins with index >= 32,
the expression (*value & BIT(i)) causes undefined behavior due
to shifting by a value >= type width.
Since 'value' is a pointer to u64, use BIT_ULL() to ensure correct
64-bit mask on all architectures.
Found by Linux Verification Center (linuxtesting.org) with Svace.
Fixes: 2c4d00cb8fc5 ("gpiolib: acpi: Use BIT() macro to increase readability")
Signed-off-by: Denis Sergeev <denserg.edu@gmail.com>
---
The ACPI specification does not define a strict upper bound for the
number of GPIO pins in the Pin Table. The value is derived from
16-bit offsets inside the resource descriptor, which theoretically
allows far more than 64 pins.
However, the current Linux GPIO ACPI OpRegion handler represents the
pin state as a single u64 value, which inherently limits the number of
addressable pins to 64. Thus, even though the specification permits
larger tables, the existing implementation already assumes a <= 64 pin
mask.
This patch fixes undefined behavior in the valid range [32, 63] on
32-bit architectures. Extending support beyond 64 pins would require
a different representation (e.g. bitmap) and is outside the scope of
this fix.
drivers/gpio/gpiolib-acpi-core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpio/gpiolib-acpi-core.c b/drivers/gpio/gpiolib-acpi-core.c
index 83dd227dbbec..d42f769eeb11 100644
--- a/drivers/gpio/gpiolib-acpi-core.c
+++ b/drivers/gpio/gpiolib-acpi-core.c
@@ -1159,7 +1159,7 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
mutex_unlock(&achip->conn_lock);
if (function == ACPI_WRITE)
- gpiod_set_raw_value_cansleep(desc, !!(*value & BIT(i)));
+ gpiod_set_raw_value_cansleep(desc, !!(*value & BIT_ULL(i)));
else
*value |= (u64)gpiod_get_raw_value_cansleep(desc) << i;
}
--
2.50.1
next reply other threads:[~2026-01-26 4:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-26 3:59 Denis Sergeev [this message]
2026-01-27 8:07 ` [PATCH] gpiolib: acpi: use BIT_ULL() for u64 mask in address space handler Mika Westerberg
2026-01-27 9:06 ` Bartosz Golaszewski
2026-01-27 9:14 ` Andy Shevchenko
2026-01-27 9:09 ` Bartosz Golaszewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260126035914.16586-1-denserg.edu@gmail.com \
--to=denserg.edu@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=brgl@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=westeri@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.