[PATCH v3 03/11] gpio: sysfs: Remove redundant check for struct gpio_chip

Tzung-Bi Shih posted 11 patches 1 month, 2 weeks ago
[PATCH v3 03/11] gpio: sysfs: Remove redundant check for struct gpio_chip
Posted by Tzung-Bi Shih 1 month, 2 weeks ago
gpiochip_sysfs_unregister() is only called by gpiochip_remove() where
the struct gpio_chip is ensured.

Remove the redundant check.

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
v3:
- Pass struct gpio_chip * only.

v2: https://lore.kernel.org/all/20260203061059.975605-4-tzungbi@kernel.org
- No changes.

v1: https://lore.kernel.org/all/20260116081036.352286-9-tzungbi@kernel.org

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

diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index cd553acf3055..97e269f30945 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -1048,11 +1048,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 *chip)
 {
+	struct gpio_device *gdev = chip->gpiodev;
 	struct gpiodev_data *data;
 	struct gpio_desc *desc;
-	struct gpio_chip *chip;
 
 	scoped_guard(mutex, &sysfs_lock) {
 		data = gdev_get_data(gdev);
@@ -1066,12 +1066,6 @@ void gpiochip_sysfs_unregister(struct gpio_device *gdev)
 		kfree(data);
 	}
 
-	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) {
 		gpiod_unexport(desc);
diff --git a/drivers/gpio/gpiolib-sysfs.h b/drivers/gpio/gpiolib-sysfs.h
index b794b396d6a5..9ee2f9dd268f 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 *chip);
 
 #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 *chip)
 {
 }
 
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 1a3fd7600835..3ff57b1e51bf 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1286,7 +1286,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.53.0.310.g728cabbaf7-goog
Re: [PATCH v3 03/11] gpio: sysfs: Remove redundant check for struct gpio_chip
Posted by Linus Walleij 1 month, 1 week ago
Hi Tzung-Bi,

thanks for your patch!

This is semantically correct, so the comments are not about that.

On Fri, Feb 13, 2026 at 10:31 AM Tzung-Bi Shih <tzungbi@kernel.org> wrote:

> gpiochip_sysfs_unregister() is only called by gpiochip_remove() where
> the struct gpio_chip is ensured.
>
> Remove the redundant check.
>
> Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>

(...)

> -void gpiochip_sysfs_unregister(struct gpio_device *gdev)
> +void gpiochip_sysfs_unregister(struct gpio_chip *chip)

Here it is chip

> -static inline void gpiochip_sysfs_unregister(struct gpio_device *gdev)
> +static inline void gpiochip_sysfs_unregister(struct gpio_chip *chip)

And here.

> @@ -1286,7 +1286,7 @@ void gpiochip_remove(struct gpio_chip *gc)
>         struct gpio_device *gdev = gc->gpiodev;

But you can see that we call it "gc" (gpiochip).

Chip is more ambiguous I think, can you use "gc" everywhere?

Either way, because the patch is so nice:
Reviewed-by: Linus Walleij <linusw@kernel.org>

Yours,
Linus Walleij
Re: [PATCH v3 03/11] gpio: sysfs: Remove redundant check for struct gpio_chip
Posted by Tzung-Bi Shih 1 month, 1 week ago
On Fri, Feb 20, 2026 at 08:51:29AM +0100, Linus Walleij wrote:
> On Fri, Feb 13, 2026 at 10:31 AM Tzung-Bi Shih <tzungbi@kernel.org> wrote:
> > -void gpiochip_sysfs_unregister(struct gpio_device *gdev)
> > +void gpiochip_sysfs_unregister(struct gpio_chip *chip)
> 
> Here it is chip
> 
> > -static inline void gpiochip_sysfs_unregister(struct gpio_device *gdev)
> > +static inline void gpiochip_sysfs_unregister(struct gpio_chip *chip)
> 
> And here.
> 
> > @@ -1286,7 +1286,7 @@ void gpiochip_remove(struct gpio_chip *gc)
> >         struct gpio_device *gdev = gc->gpiodev;
> 
> But you can see that we call it "gc" (gpiochip).
> 
> Chip is more ambiguous I think, can you use "gc" everywhere?

Ack, will fix in v4.