* [PATCH] pinctrl: airoha: Use unsigned long for bit search
@ 2024-11-17 11:45 Kees Cook
2024-11-18 6:52 ` AngeloGioacchino Del Regno
2024-11-18 22:58 ` Linus Walleij
0 siblings, 2 replies; 3+ messages in thread
From: Kees Cook @ 2024-11-17 11:45 UTC (permalink / raw)
To: Lorenzo Bianconi
Cc: Kees Cook, Sean Wang, Linus Walleij, linux-mediatek, linux-gpio,
Matthias Brugger, AngeloGioacchino Del Regno, linux-kernel,
linux-arm-kernel, linux-hardening
Instead of risking alignment problems and causing (false positive) array
bound warnings when casting a u32 to (64-bit) unsigned long, just use a
native unsigned long for doing bit searches. Avoids warning with GCC 15's
-Warray-bounds -fdiagnostics-details:
In file included from ../include/linux/bitmap.h:11,
from ../include/linux/cpumask.h:12,
from ../arch/x86/include/asm/paravirt.h:21,
from ../arch/x86/include/asm/irqflags.h:80,
from ../include/linux/irqflags.h:18,
from ../include/linux/spinlock.h:59,
from ../include/linux/irq.h:14,
from ../include/linux/irqchip/chained_irq.h:10,
from ../include/linux/gpio/driver.h:8,
from ../drivers/pinctrl/mediatek/pinctrl-airoha.c:11:
In function 'find_next_bit',
inlined from 'airoha_irq_handler' at ../drivers/pinctrl/mediatek/pinctrl-airoha.c:2394:3:
../include/linux/find.h:65:23: error: array subscript 'long unsigned int[0]' is partly outside array bounds of 'u32[1]' {aka 'unsigned int[1]'} [-Werror=array-bounds=]
65 | val = *addr & GENMASK(size - 1, offset);
| ^~~~~
../drivers/pinctrl/mediatek/pinctrl-airoha.c: In function 'airoha_irq_handler':
../drivers/pinctrl/mediatek/pinctrl-airoha.c:2387:21: note: object 'status' of size 4
2387 | u32 status;
| ^~~~~~
Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: Lorenzo Bianconi <lorenzo@kernel.org>
Cc: Sean Wang <sean.wang@kernel.org>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: linux-mediatek@lists.infradead.org
Cc: linux-gpio@vger.kernel.org
---
drivers/pinctrl/mediatek/pinctrl-airoha.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/pinctrl/mediatek/pinctrl-airoha.c b/drivers/pinctrl/mediatek/pinctrl-airoha.c
index 7692e6d9b871..547a798b71c8 100644
--- a/drivers/pinctrl/mediatek/pinctrl-airoha.c
+++ b/drivers/pinctrl/mediatek/pinctrl-airoha.c
@@ -2384,15 +2384,16 @@ static irqreturn_t airoha_irq_handler(int irq, void *data)
for (i = 0; i < ARRAY_SIZE(irq_status_regs); i++) {
struct gpio_irq_chip *girq = &pinctrl->gpiochip.chip.irq;
- u32 status;
+ u32 regmap;
+ unsigned long status;
int irq;
if (regmap_read(pinctrl->regmap, pinctrl->gpiochip.status[i],
- &status))
+ ®map))
continue;
- for_each_set_bit(irq, (unsigned long *)&status,
- AIROHA_PIN_BANK_SIZE) {
+ status = regmap;
+ for_each_set_bit(irq, &status, AIROHA_PIN_BANK_SIZE) {
u32 offset = irq + i * AIROHA_PIN_BANK_SIZE;
generic_handle_irq(irq_find_mapping(girq->domain,
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] pinctrl: airoha: Use unsigned long for bit search
2024-11-17 11:45 [PATCH] pinctrl: airoha: Use unsigned long for bit search Kees Cook
@ 2024-11-18 6:52 ` AngeloGioacchino Del Regno
2024-11-18 22:58 ` Linus Walleij
1 sibling, 0 replies; 3+ messages in thread
From: AngeloGioacchino Del Regno @ 2024-11-18 6:52 UTC (permalink / raw)
To: Kees Cook, Lorenzo Bianconi
Cc: Sean Wang, Linus Walleij, linux-mediatek, linux-gpio,
Matthias Brugger, linux-kernel, linux-arm-kernel, linux-hardening
Il 17/11/24 12:45, Kees Cook ha scritto:
> Instead of risking alignment problems and causing (false positive) array
> bound warnings when casting a u32 to (64-bit) unsigned long, just use a
> native unsigned long for doing bit searches. Avoids warning with GCC 15's
> -Warray-bounds -fdiagnostics-details:
>
> In file included from ../include/linux/bitmap.h:11,
> from ../include/linux/cpumask.h:12,
> from ../arch/x86/include/asm/paravirt.h:21,
> from ../arch/x86/include/asm/irqflags.h:80,
> from ../include/linux/irqflags.h:18,
> from ../include/linux/spinlock.h:59,
> from ../include/linux/irq.h:14,
> from ../include/linux/irqchip/chained_irq.h:10,
> from ../include/linux/gpio/driver.h:8,
> from ../drivers/pinctrl/mediatek/pinctrl-airoha.c:11:
> In function 'find_next_bit',
> inlined from 'airoha_irq_handler' at ../drivers/pinctrl/mediatek/pinctrl-airoha.c:2394:3:
> ../include/linux/find.h:65:23: error: array subscript 'long unsigned int[0]' is partly outside array bounds of 'u32[1]' {aka 'unsigned int[1]'} [-Werror=array-bounds=]
> 65 | val = *addr & GENMASK(size - 1, offset);
> | ^~~~~
> ../drivers/pinctrl/mediatek/pinctrl-airoha.c: In function 'airoha_irq_handler':
> ../drivers/pinctrl/mediatek/pinctrl-airoha.c:2387:21: note: object 'status' of size 4
> 2387 | u32 status;
> | ^~~~~~
>
> Signed-off-by: Kees Cook <kees@kernel.org>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] pinctrl: airoha: Use unsigned long for bit search
2024-11-17 11:45 [PATCH] pinctrl: airoha: Use unsigned long for bit search Kees Cook
2024-11-18 6:52 ` AngeloGioacchino Del Regno
@ 2024-11-18 22:58 ` Linus Walleij
1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2024-11-18 22:58 UTC (permalink / raw)
To: Kees Cook
Cc: Lorenzo Bianconi, Sean Wang, linux-mediatek, linux-gpio,
Matthias Brugger, AngeloGioacchino Del Regno, linux-kernel,
linux-arm-kernel, linux-hardening
On Sun, Nov 17, 2024 at 12:45 PM Kees Cook <kees@kernel.org> wrote:
> Instead of risking alignment problems and causing (false positive) array
> bound warnings when casting a u32 to (64-bit) unsigned long, just use a
> native unsigned long for doing bit searches. Avoids warning with GCC 15's
> -Warray-bounds -fdiagnostics-details:
>
> In file included from ../include/linux/bitmap.h:11,
> from ../include/linux/cpumask.h:12,
> from ../arch/x86/include/asm/paravirt.h:21,
> from ../arch/x86/include/asm/irqflags.h:80,
> from ../include/linux/irqflags.h:18,
> from ../include/linux/spinlock.h:59,
> from ../include/linux/irq.h:14,
> from ../include/linux/irqchip/chained_irq.h:10,
> from ../include/linux/gpio/driver.h:8,
> from ../drivers/pinctrl/mediatek/pinctrl-airoha.c:11:
> In function 'find_next_bit',
> inlined from 'airoha_irq_handler' at ../drivers/pinctrl/mediatek/pinctrl-airoha.c:2394:3:
> ../include/linux/find.h:65:23: error: array subscript 'long unsigned int[0]' is partly outside array bounds of 'u32[1]' {aka 'unsigned int[1]'} [-Werror=array-bounds=]
> 65 | val = *addr & GENMASK(size - 1, offset);
> | ^~~~~
> ../drivers/pinctrl/mediatek/pinctrl-airoha.c: In function 'airoha_irq_handler':
> ../drivers/pinctrl/mediatek/pinctrl-airoha.c:2387:21: note: object 'status' of size 4
> 2387 | u32 status;
> | ^~~~~~
>
> Signed-off-by: Kees Cook <kees@kernel.org>
Patch applied, thanks Kees!
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-11-18 22:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-17 11:45 [PATCH] pinctrl: airoha: Use unsigned long for bit search Kees Cook
2024-11-18 6:52 ` AngeloGioacchino Del Regno
2024-11-18 22:58 ` Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).