Skip to content

Commit 207270d

Browse files
danc86linusw
authored andcommitted
gpiolib: hold gpio devices lock until ->descs array is initialised
If a driver consuming the GPIO chip is being probed at the same time as the GPIO driver is registering the chip, it is possible for the consuming driver to see the ->descs array in an uninitialised state. For example, the gpio-keys-polled driver can fail like this: kernel: gpiod_request: invalid GPIO (no device) kernel: gpio-keys-polled PRP0001:07: failed to get gpio: -22 kernel: gpio-keys-polled: probe of PRP0001:07 failed with error -22 This patch makes gpiochip_add() hold the lock protecting gpio_devices until it has finished setting desc->gdev on the newly inserted list entry. Signed-off-by: Dan Callaghan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent 0d311d8 commit 207270d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/gpio/gpiolib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,11 +1486,11 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
14861486
goto err_free_label;
14871487
}
14881488

1489-
spin_unlock_irqrestore(&gpio_lock, flags);
1490-
14911489
for (i = 0; i < chip->ngpio; i++)
14921490
gdev->descs[i].gdev = gdev;
14931491

1492+
spin_unlock_irqrestore(&gpio_lock, flags);
1493+
14941494
#ifdef CONFIG_PINCTRL
14951495
INIT_LIST_HEAD(&gdev->pin_ranges);
14961496
#endif

0 commit comments

Comments
 (0)