* [PATCH] gpiolib: hold gpio devices lock until ->descs array is initialised
@ 2019-12-02 4:59 Dan Callaghan
0 siblings, 0 replies; only message in thread
From: Dan Callaghan @ 2019-12-02 4:59 UTC (permalink / raw)
To: linux-gpio; +Cc: Dan Callaghan
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 <dan.callaghan@opengear.com>
---
drivers/gpio/gpiolib.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index dce0b31f4125..93eec6dbd9c7 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1487,11 +1487,11 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
goto err_free_label;
}
- spin_unlock_irqrestore(&gpio_lock, flags);
-
for (i = 0; i < chip->ngpio; i++)
gdev->descs[i].gdev = gdev;
+ spin_unlock_irqrestore(&gpio_lock, flags);
+
#ifdef CONFIG_PINCTRL
INIT_LIST_HEAD(&gdev->pin_ranges);
#endif
--
2.21.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, back to index
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-02 4:59 [PATCH] gpiolib: hold gpio devices lock until ->descs array is initialised Dan Callaghan
Linux-GPIO Archive on lore.kernel.org
Archives are clonable:
git clone --mirror https://lore.kernel.org/linux-gpio/0 linux-gpio/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 linux-gpio linux-gpio/ https://lore.kernel.org/linux-gpio \
linux-gpio@vger.kernel.org
public-inbox-index linux-gpio
Example config snippet for mirrors
Newsgroup available over NNTP:
nntp://nntp.lore.kernel.org/org.kernel.vger.linux-gpio
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git