[PATCH v4 5/6] gpio: cdev: Don't check struct gpio_chip in gpio_chrdev_open()

From: Tzung-Bi Shih

Date: Mon Feb 23 2026 - 01:18:33 EST


It's harmless even if: chrdev_open() and cdev_device_del() run at the
same time, and gpio_chrdev_open() gets called after the underlying GPIO
chip has gone. The subsequent file operations check the availability
of struct gpio_chip anyway.

Don't check struct gpio_chip in gpio_chrdev_open().

Reviewed-by: Linus Walleij <linusw@xxxxxxxxxx>
Signed-off-by: Tzung-Bi Shih <tzungbi@xxxxxxxxxx>
---
v4:
- Add R-b tag.

v3: https://lore.kernel.org/all/20260213092958.864411-6-tzungbi@xxxxxxxxxx
- No changes.

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

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

drivers/gpio/gpiolib-cdev.c | 6 ------
1 file changed, 6 deletions(-)

diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index a154b04e9316..475ad185f915 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -2689,12 +2689,6 @@ static int gpio_chrdev_open(struct inode *inode, struct file *file)
struct gpio_chardev_data *cdev;
int ret = -ENOMEM;

- guard(srcu)(&gdev->srcu);
-
- /* Fail on open if the backing gpiochip is gone */
- if (!rcu_access_pointer(gdev->chip))
- return -ENODEV;
-
cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
if (!cdev)
return -ENOMEM;
--
2.51.0