Skip to content

Commit 0d7fa0e

Browse files
author
Bartosz Golaszewski
committed
gpio: don't let lockdep complain about inherently dangerous RCU usage
There are two legacy, deprecated functions - gpiod_to_chip() and gpio_device_get_chip() - that still have users in tree. They return the address of the SRCU-protected chip outside of the read-only critical sections. They are inherently dangerous and the users should convert to safer alternatives. Let's explicitly silence lockdep warnings by using rcu_dereference_check(ptr, 1). While at it: reuse gpio_device_get_chip() in gpiod_to_chip(). Fixes: d83cee3 ("gpio: protect the pointer to gpio_chip in gpio_device with SRCU") Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-lkp/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent d82b9e0 commit 0d7fa0e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/gpio/gpiolib.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc)
221221
{
222222
if (!desc)
223223
return NULL;
224-
return rcu_dereference(desc->gdev->chip);
224+
225+
return gpio_device_get_chip(desc->gdev);
225226
}
226227
EXPORT_SYMBOL_GPL(gpiod_to_chip);
227228

@@ -291,7 +292,7 @@ EXPORT_SYMBOL(gpio_device_get_label);
291292
*/
292293
struct gpio_chip *gpio_device_get_chip(struct gpio_device *gdev)
293294
{
294-
return rcu_dereference(gdev->chip);
295+
return rcu_dereference_check(gdev->chip, 1);
295296
}
296297
EXPORT_SYMBOL_GPL(gpio_device_get_chip);
297298

0 commit comments

Comments
 (0)