Skip to content

Commit 47d8b4c

Browse files
author
Bartosz Golaszewski
committed
gpio: add SRCU infrastructure to struct gpio_device
Add the SRCU struct to GPIO device. It will be used to serialize access to the GPIO chip pointer. Initialize and clean it up where applicable. Signed-off-by: Bartosz Golaszewski <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Acked-by: Andy Shevchenko <[email protected]>
1 parent 8a5b477 commit 47d8b4c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

drivers/gpio/gpiolib.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ static void gpiodev_release(struct device *dev)
680680
ida_free(&gpio_ida, gdev->id);
681681
kfree_const(gdev->label);
682682
kfree(gdev->descs);
683+
cleanup_srcu_struct(&gdev->srcu);
683684
kfree(gdev);
684685
}
685686

@@ -948,22 +949,26 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
948949
BLOCKING_INIT_NOTIFIER_HEAD(&gdev->device_notifier);
949950
init_rwsem(&gdev->sem);
950951

952+
ret = init_srcu_struct(&gdev->srcu);
953+
if (ret)
954+
goto err_remove_from_list;
955+
951956
#ifdef CONFIG_PINCTRL
952957
INIT_LIST_HEAD(&gdev->pin_ranges);
953958
#endif
954959

955960
if (gc->names) {
956961
ret = gpiochip_set_desc_names(gc);
957962
if (ret)
958-
goto err_remove_from_list;
963+
goto err_cleanup_gdev_srcu;
959964
}
960965
ret = gpiochip_set_names(gc);
961966
if (ret)
962-
goto err_remove_from_list;
967+
goto err_cleanup_gdev_srcu;
963968

964969
ret = gpiochip_init_valid_mask(gc);
965970
if (ret)
966-
goto err_remove_from_list;
971+
goto err_cleanup_gdev_srcu;
967972

968973
ret = of_gpiochip_add(gc);
969974
if (ret)
@@ -1038,6 +1043,8 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
10381043
err_free_gpiochip_mask:
10391044
gpiochip_remove_pin_ranges(gc);
10401045
gpiochip_free_valid_mask(gc);
1046+
err_cleanup_gdev_srcu:
1047+
cleanup_srcu_struct(&gdev->srcu);
10411048
err_remove_from_list:
10421049
scoped_guard(mutex, &gpio_devices_lock)
10431050
list_del_rcu(&gdev->list);

drivers/gpio/gpiolib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
* @sem: protects the structure from a NULL-pointer dereference of @chip by
5050
* user-space operations when the device gets unregistered during
5151
* a hot-unplug event
52+
* @srcu: protects the pointer to the underlying GPIO chip
5253
* @pin_ranges: range of pins served by the GPIO driver
5354
*
5455
* This state container holds most of the runtime variable data
@@ -73,6 +74,7 @@ struct gpio_device {
7374
struct blocking_notifier_head line_state_notifier;
7475
struct blocking_notifier_head device_notifier;
7576
struct rw_semaphore sem;
77+
struct srcu_struct srcu;
7678

7779
#ifdef CONFIG_PINCTRL
7880
/*

0 commit comments

Comments
 (0)