gpiochip_sysfs_unregister() is only called by gpiochip_remove() where
the struct gpio_chip is ensured.

Remove the redundant check.

Reviewed-by: Linus Walleij <[email protected]>
Signed-off-by: Tzung-Bi Shih <[email protected]>
---
v4:
- Add R-b tag.
- To be consistent, rename `chip` -> `gc`.

v3: https://lore.kernel.org/all/[email protected]
- Pass struct gpio_chip * only.

v2: https://lore.kernel.org/all/[email protected]
- No changes.

v1: https://lore.kernel.org/all/[email protected]

 drivers/gpio/gpiolib-sysfs.c | 11 +++--------
 drivers/gpio/gpiolib-sysfs.h |  4 ++--
 drivers/gpio/gpiolib.c       |  2 +-
 3 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 270e8060e761..1c25a7dd3db4 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -1053,11 +1053,11 @@ int gpiochip_sysfs_register(struct gpio_device *gdev)
        return 0;
 }
 
-void gpiochip_sysfs_unregister(struct gpio_device *gdev)
+void gpiochip_sysfs_unregister(struct gpio_chip *gc)
 {
+       struct gpio_device *gdev = gc->gpiodev;
        struct gpiodev_data *data;
        struct gpio_desc *desc;
-       struct gpio_chip *chip;
 
        guard(mutex)(&sysfs_lock);
 
@@ -1065,13 +1065,8 @@ void gpiochip_sysfs_unregister(struct gpio_device *gdev)
        if (!data)
                return;
 
-       guard(srcu)(&gdev->srcu);
-       chip = srcu_dereference(gdev->chip, &gdev->srcu);
-       if (!chip)
-               return;
-
        /* unregister gpiod class devices owned by sysfs */
-       for_each_gpio_desc_with_flag(chip, desc, GPIOD_FLAG_SYSFS) {
+       for_each_gpio_desc_with_flag(gc, desc, GPIOD_FLAG_SYSFS) {
                gpiod_unexport_unlocked(desc);
                gpiod_free(desc);
        }
diff --git a/drivers/gpio/gpiolib-sysfs.h b/drivers/gpio/gpiolib-sysfs.h
index b794b396d6a5..fd5db5384681 100644
--- a/drivers/gpio/gpiolib-sysfs.h
+++ b/drivers/gpio/gpiolib-sysfs.h
@@ -8,7 +8,7 @@ struct gpio_device;
 #ifdef CONFIG_GPIO_SYSFS
 
 int gpiochip_sysfs_register(struct gpio_device *gdev);
-void gpiochip_sysfs_unregister(struct gpio_device *gdev);
+void gpiochip_sysfs_unregister(struct gpio_chip *gc);
 
 #else
 
@@ -17,7 +17,7 @@ static inline int gpiochip_sysfs_register(struct gpio_device 
*gdev)
        return 0;
 }
 
-static inline void gpiochip_sysfs_unregister(struct gpio_device *gdev)
+static inline void gpiochip_sysfs_unregister(struct gpio_chip *gc)
 {
 }
 
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 08a3697dbd5a..d5070c538ba5 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1285,7 +1285,7 @@ void gpiochip_remove(struct gpio_chip *gc)
        struct gpio_device *gdev = gc->gpiodev;
 
        /* FIXME: should the legacy sysfs handling be moved to gpio_device? */
-       gpiochip_sysfs_unregister(gdev);
+       gpiochip_sysfs_unregister(gc);
        gpiochip_free_hogs(gc);
        gpiochip_free_remaining_irqs(gc);
 
-- 
2.51.0


Reply via email to