* [PATCH] gpiolib: acpi: use BIT_ULL() for u64 mask in address space handler
@ 2026-01-26 3:59 Denis Sergeev
2026-01-27 8:07 ` Mika Westerberg
2026-01-27 9:09 ` Bartosz Golaszewski
0 siblings, 2 replies; 5+ messages in thread
From: Denis Sergeev @ 2026-01-26 3:59 UTC (permalink / raw)
To: westeri, andriy.shevchenko, linusw, brgl
Cc: linux-gpio, linux-acpi, linux-kernel, lvc-project, Denis Sergeev
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] gpiolib: acpi: use BIT_ULL() for u64 mask in address space handler
2026-01-26 3:59 [PATCH] gpiolib: acpi: use BIT_ULL() for u64 mask in address space handler Denis Sergeev
@ 2026-01-27 8:07 ` Mika Westerberg
2026-01-27 9:06 ` Bartosz Golaszewski
2026-01-27 9:09 ` Bartosz Golaszewski
1 sibling, 1 reply; 5+ messages in thread
From: Mika Westerberg @ 2026-01-27 8:07 UTC (permalink / raw)
To: Denis Sergeev
Cc: westeri, andriy.shevchenko, linusw, brgl, linux-gpio, linux-acpi,
linux-kernel, lvc-project
On Mon, Jan 26, 2026 at 06:59:14AM +0300, Denis Sergeev wrote:
> 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>
Reviewed-by: Mika Westerberg <westeri@kernel.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gpiolib: acpi: use BIT_ULL() for u64 mask in address space handler
2026-01-27 8:07 ` Mika Westerberg
@ 2026-01-27 9:06 ` Bartosz Golaszewski
2026-01-27 9:14 ` Andy Shevchenko
0 siblings, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2026-01-27 9:06 UTC (permalink / raw)
To: Mika Westerberg
Cc: Denis Sergeev, westeri, andriy.shevchenko, linusw, linux-gpio,
linux-acpi, linux-kernel, lvc-project
On Tue, Jan 27, 2026 at 9:08 AM Mika Westerberg
<mika.westerberg@linux.intel.com> wrote:
>
> On Mon, Jan 26, 2026 at 06:59:14AM +0300, Denis Sergeev wrote:
> > 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>
>
> Reviewed-by: Mika Westerberg <westeri@kernel.org>
I'll queue this for v6.19-rc8.
Bart
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gpiolib: acpi: use BIT_ULL() for u64 mask in address space handler
2026-01-26 3:59 [PATCH] gpiolib: acpi: use BIT_ULL() for u64 mask in address space handler Denis Sergeev
2026-01-27 8:07 ` Mika Westerberg
@ 2026-01-27 9:09 ` Bartosz Golaszewski
1 sibling, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2026-01-27 9:09 UTC (permalink / raw)
To: westeri, andriy.shevchenko, linusw, brgl, Denis Sergeev
Cc: Bartosz Golaszewski, linux-gpio, linux-acpi, linux-kernel,
lvc-project
On Mon, 26 Jan 2026 06:59:14 +0300, Denis Sergeev wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] gpiolib: acpi: use BIT_ULL() for u64 mask in address space handler
commit: 59084c564c412b1d537f90bd70fa1d6bfb584e82
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gpiolib: acpi: use BIT_ULL() for u64 mask in address space handler
2026-01-27 9:06 ` Bartosz Golaszewski
@ 2026-01-27 9:14 ` Andy Shevchenko
0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2026-01-27 9:14 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Mika Westerberg, Denis Sergeev, westeri, linusw, linux-gpio,
linux-acpi, linux-kernel, lvc-project
On Tue, Jan 27, 2026 at 10:06:33AM +0100, Bartosz Golaszewski wrote:
> On Tue, Jan 27, 2026 at 9:08 AM Mika Westerberg
> <mika.westerberg@linux.intel.com> wrote:
> >
> > On Mon, Jan 26, 2026 at 06:59:14AM +0300, Denis Sergeev wrote:
> > > 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>
> >
> > Reviewed-by: Mika Westerberg <westeri@kernel.org>
>
> I'll queue this for v6.19-rc8.
This is half-baked solution... But okay, let's shut up at least the stream of
this type of "fixes" in this file.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-01-27 9:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-26 3:59 [PATCH] gpiolib: acpi: use BIT_ULL() for u64 mask in address space handler Denis Sergeev
2026-01-27 8:07 ` Mika Westerberg
2026-01-27 9:06 ` Bartosz Golaszewski
2026-01-27 9:14 ` Andy Shevchenko
2026-01-27 9:09 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox