gpio: remove the RW semaphore from the GPIO device
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Wed, 24 Jan 2024 16:02:03 +0000 (17:02 +0100)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Mon, 12 Feb 2024 10:00:55 +0000 (11:00 +0100)
With all accesses to gdev->chip being protected with SRCU, we can now
remove the RW-semaphore specific to the character device which
fulfilled the same role up to this point.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
drivers/gpio/gpiolib.c
drivers/gpio/gpiolib.h

index 1a9d045b5a6b95079f5c6b23b1615d869ef9ad5b..875b40376c0b955bf9b97b2379f2880e3806d40a 100644 (file)
@@ -963,7 +963,6 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
 
        BLOCKING_INIT_NOTIFIER_HEAD(&gdev->line_state_notifier);
        BLOCKING_INIT_NOTIFIER_HEAD(&gdev->device_notifier);
-       init_rwsem(&gdev->sem);
 
        ret = init_srcu_struct(&gdev->srcu);
        if (ret)
@@ -1102,8 +1101,6 @@ void gpiochip_remove(struct gpio_chip *gc)
        struct gpio_device *gdev = gc->gpiodev;
        unsigned int i;
 
-       down_write(&gdev->sem);
-
        /* FIXME: should the legacy sysfs handling be moved to gpio_device? */
        gpiochip_sysfs_unregister(gdev);
        gpiochip_free_hogs(gc);
@@ -1142,7 +1139,6 @@ void gpiochip_remove(struct gpio_chip *gc)
         * gone.
         */
        gcdev_unregister(gdev);
-       up_write(&gdev->sem);
        gpio_device_put(gdev);
 }
 EXPORT_SYMBOL_GPL(gpiochip_remove);
index b3810f7d286a756e60bd444b5e9512c4cf06d7c6..07443d26cbcae895c0f52f19008f3538847d6ec7 100644 (file)
@@ -16,7 +16,6 @@
 #include <linux/gpio/driver.h>
 #include <linux/module.h>
 #include <linux/notifier.h>
-#include <linux/rwsem.h>
 #include <linux/srcu.h>
 
 #define GPIOCHIP_NAME  "gpiochip"
@@ -46,9 +45,6 @@
  *                       requested, released or reconfigured
  * @device_notifier: used to notify character device wait queues about the GPIO
  *                   device being unregistered
- * @sem: protects the structure from a NULL-pointer dereference of @chip by
- *       user-space operations when the device gets unregistered during
- *       a hot-unplug event
  * @srcu: protects the pointer to the underlying GPIO chip
  * @pin_ranges: range of pins served by the GPIO driver
  *
@@ -73,7 +69,6 @@ struct gpio_device {
        struct list_head        list;
        struct blocking_notifier_head line_state_notifier;
        struct blocking_notifier_head device_notifier;
-       struct rw_semaphore     sem;
        struct srcu_struct      srcu;
 
 #ifdef CONFIG_PINCTRL