gpio: sysfs: fix chip removal with GPIOs exported over sysfs
authorBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Thu, 12 Feb 2026 13:35:05 +0000 (14:35 +0100)
committerBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Wed, 18 Feb 2026 08:42:56 +0000 (09:42 +0100)
commit6766f59012301f1bf3f46c6e7149caca45d92309
tree0b7b152397d55e83718554d39805e9f5c79ab3de
parentff91965ad8b214e0771bc5a15253f14f583a7649
gpio: sysfs: fix chip removal with GPIOs exported over sysfs

Currently if we export a GPIO over sysfs and unbind the parent GPIO
controller, the exported attribute will remain under /sys/class/gpio
because once we remove the parent device, we can no longer associate the
descriptor with it in gpiod_unexport() and never drop the final
reference.

Rework the teardown code: provide an unlocked variant of
gpiod_unexport() and remove all exported GPIOs with the sysfs_lock taken
before unregistering the parent device itself. This is done to prevent
any new exports happening before we unregister the device completely.

Cc: stable@vger.kernel.org
Fixes: 1cd53df733c2 ("gpio: sysfs: don't look up exported lines as class devices")
Link: https://patch.msgid.link/20260212133505.81516-1-bartosz.golaszewski@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
drivers/gpio/gpiolib-sysfs.c