Skip to content

Commit 1b73e58

Browse files
Marc Zyngierlinusw
authored andcommitted
pinctrl: stmfx: Fix hazardous u8[] to unsigned long cast
Casting a small array of u8 to an unsigned long is *never* OK: - it does funny thing when the array size is less than that of a long, as it accesses random places in the stack - it makes everything even more fun with a BE kernel Fix this by building the unsigned long used as a bitmap byte by byte, in a way that works across endianess and has no undefined behaviours. An extra BUILD_BUG_ON() catches the unlikely case where the array would be larger than a single unsigned long. Fixes: 1490d9f ("pinctrl: Add STMFX GPIO expander Pinctrl/GPIO driver") Signed-off-by: Marc Zyngier <[email protected]> Cc: [email protected] Cc: Amelie Delaunay <[email protected]> Cc: Linus Walleij <[email protected]> Cc: Maxime Coquelin <[email protected]> Cc: Alexandre Torgue <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent a022135 commit 1b73e58

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/pinctrl/pinctrl-stmfx.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ static irqreturn_t stmfx_pinctrl_irq_thread_fn(int irq, void *dev_id)
566566
u8 pending[NR_GPIO_REGS];
567567
u8 src[NR_GPIO_REGS] = {0, 0, 0};
568568
unsigned long n, status;
569-
int ret;
569+
int i, ret;
570570

571571
ret = regmap_bulk_read(pctl->stmfx->map, STMFX_REG_IRQ_GPI_PENDING,
572572
&pending, NR_GPIO_REGS);
@@ -576,7 +576,9 @@ static irqreturn_t stmfx_pinctrl_irq_thread_fn(int irq, void *dev_id)
576576
regmap_bulk_write(pctl->stmfx->map, STMFX_REG_IRQ_GPI_SRC,
577577
src, NR_GPIO_REGS);
578578

579-
status = *(unsigned long *)pending;
579+
BUILD_BUG_ON(NR_GPIO_REGS > sizeof(status));
580+
for (i = 0, status = 0; i < NR_GPIO_REGS; i++)
581+
status |= (unsigned long)pending[i] << (i * 8);
580582
for_each_set_bit(n, &status, gc->ngpio) {
581583
handle_nested_irq(irq_find_mapping(gc->irq.domain, n));
582584
stmfx_pinctrl_irq_toggle_trigger(pctl, n);

0 commit comments

Comments
 (0)