Skip to content

Commit 815a1b5

Browse files
author
Bartosz Golaszewski
committed
gpio: take the SRCU read lock in gpiod_hog()
gpiod_hog() may be called without the gpio_device SRCU read lock taken so we need to do it here as well. It's alright if someone else is already holding the lock as SRCU read critical sections can be nested. 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]> Reviewed-by: Linus Walleij <[email protected]> Acked-by: Paul E. McKenney <[email protected]>
1 parent e3f927f commit 815a1b5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

drivers/gpio/gpiolib.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4492,24 +4492,27 @@ EXPORT_SYMBOL_GPL(gpiod_get_index_optional);
44924492
int gpiod_hog(struct gpio_desc *desc, const char *name,
44934493
unsigned long lflags, enum gpiod_flags dflags)
44944494
{
4495-
struct gpio_chip *gc;
4495+
struct gpio_device *gdev = desc->gdev;
44964496
struct gpio_desc *local_desc;
44974497
int hwnum;
44984498
int ret;
44994499

4500+
CLASS(gpio_chip_guard, guard)(desc);
4501+
if (!guard.gc)
4502+
return -ENODEV;
4503+
45004504
if (test_and_set_bit(FLAG_IS_HOGGED, &desc->flags))
45014505
return 0;
45024506

4503-
gc = gpiod_to_chip(desc);
45044507
hwnum = gpio_chip_hwgpio(desc);
45054508

4506-
local_desc = gpiochip_request_own_desc(gc, hwnum, name,
4509+
local_desc = gpiochip_request_own_desc(guard.gc, hwnum, name,
45074510
lflags, dflags);
45084511
if (IS_ERR(local_desc)) {
45094512
clear_bit(FLAG_IS_HOGGED, &desc->flags);
45104513
ret = PTR_ERR(local_desc);
45114514
pr_err("requesting hog GPIO %s (chip %s, offset %d) failed, %d\n",
4512-
name, gc->label, hwnum, ret);
4515+
name, gdev->label, hwnum, ret);
45134516
return ret;
45144517
}
45154518

0 commit comments

Comments
 (0)