]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
gpiolib: add a second blocking notifier to struct gpio_device
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Thu, 17 Aug 2023 11:59:05 +0000 (13:59 +0200)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Mon, 21 Aug 2023 13:57:05 +0000 (15:57 +0200)
Add a new blocking notifier to struct gpio_device and use it to notify
subscribers about the GPIO device being unregistered from the device
model.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
drivers/gpio/gpiolib-cdev.c
drivers/gpio/gpiolib.c
drivers/gpio/gpiolib.h

index 91bdd3b928b562d7263f4112a49fa23e6dbdc9a1..fec446510028ea9a493a65374c57d796bf371f4e 100644 (file)
@@ -2748,4 +2748,5 @@ int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt)
 void gpiolib_cdev_unregister(struct gpio_device *gdev)
 {
        cdev_device_del(&gdev->chrdev, &gdev->dev);
+       blocking_notifier_call_chain(&gdev->device_notifier, 0, NULL);
 }
index 38640df1d7988928ad1fe23a02fbfa3e38257b94..8f74e0bb2a5ca570600ec906d9fccc76d95a13ea 100644 (file)
@@ -848,6 +848,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
        spin_unlock_irqrestore(&gpio_lock, flags);
 
        BLOCKING_INIT_NOTIFIER_HEAD(&gdev->line_state_notifier);
+       BLOCKING_INIT_NOTIFIER_HEAD(&gdev->device_notifier);
        init_rwsem(&gdev->sem);
 
 #ifdef CONFIG_PINCTRL
index 11a5e02f317d5f3b8cd7503e3743d1639ab3aecc..e860ed434bc2aa3c304564470fe04f8b55fddc19 100644 (file)
@@ -41,6 +41,8 @@
  * @list: links gpio_device:s together for traversal
  * @line_state_notifier: used to notify subscribers about lines being
  *                       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
@@ -65,6 +67,7 @@ struct gpio_device {
        void                    *data;
        struct list_head        list;
        struct blocking_notifier_head line_state_notifier;
+       struct blocking_notifier_head device_notifier;
        struct rw_semaphore     sem;
 
 #ifdef CONFIG_PINCTRL