[PATCH v3 3/5] gpiolib: clear debounce period before the "requested" flag
From: Bartosz Golaszewski
Date: Tue Nov 10 2026 - 09:01:04 EST
The debounce_period_us field is protected by the GPIOD_FLAG_REQUESTED
flag, so it should be cleared before the flag, else it could potentially
race with a new request.
Suggested-by: Kent Gibson <warthog618@xxxxxxxxx>
Closes: https://lore.kernel.org/all/20261105042905.GB8436@rigel/
Fixes: 81625f362497 ("gpio: cdev: go back to storing debounce period in the GPIO descriptor")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>
---
drivers/gpio/gpiolib.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 1285a993a1ceeff719142ad019451d2e9af6a520..ce8531a8e95dd3bdff7ca32f4e486b329a19afaf 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2699,6 +2699,10 @@ void gpiod_free_commit(struct gpio_desc *desc)
if (guard.gc->free)
guard.gc->free(guard.gc, gpiod_hwgpio(desc));
+#ifdef CONFIG_GPIO_CDEV
+ WRITE_ONCE(desc->debounce_period_us, 0);
+#endif
+
clear_bit(GPIOD_FLAG_ACTIVE_LOW, &flags);
clear_bit(GPIOD_FLAG_REQUESTED, &flags);
clear_bit(GPIOD_FLAG_OPEN_DRAIN, &flags);
@@ -2716,9 +2720,6 @@ void gpiod_free_commit(struct gpio_desc *desc)
#endif
desc_set_label(desc, NULL);
WRITE_ONCE(desc->flags, flags);
-#ifdef CONFIG_GPIO_CDEV
- WRITE_ONCE(desc->debounce_period_us, 0);
-#endif
gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_RELEASED);
}
}
--
2.47.3