[PATCH v3 0/5] gpiolib: improve concurrent access to the flags field of struct gpio_desc
From: Bartosz Golaszewski
Date: Tue Nov 10 2026 - 09:36:11 EST
This is a follow-up to our discussion[1] about desc->flags and possible
races with users who don't/can't synchronize with other means.
It's an attempt to use try_cmpxchg() to update only the required flags
atomically where needed + minor fixes using atomic variants of bitops
where it makes sense.
[1] https://lore.kernel.org/all/20261015153714.GA105746@rigel/
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>
---
Changes in v3:
- Don't pull in bitops.h when including bitmap.h
- Improve coding style: fix indentation, set mask later in the function,
make lines longer and more readable
- Use the right Fixes tags
- Link to v2: https://patch.msgid.link/20261109-gpio-desc-flags-atomic-v2-0-c4c54b476628@xxxxxxxxxxxxxxxx
Changes in v2:
- Drop the custom gpiod_update_flags() function and use the existing
set_mask_bits() macro instead
- Add a patch clearing debounce_period_us before GPIOD_FLAG_REQUESTED as
suggested by Kent
- Rename the functions updating flags in gpiolib-cdev.c
- Don't rename the flags variable
- Link to v1: https://patch.msgid.link/20261104-gpio-desc-flags-atomic-v1-0-e23cedf619ba@xxxxxxxxxxxxxxxx
---
Bartosz Golaszewski (5):
gpiolib: don't overwrite the entire flags field in gpiod_get_direction()
gpio: shared: use atomic set_bit() for descriptor flags
gpiolib: clear debounce period before the "requested" flag
gpiolib: don't overwrite the entire flags field in gpiod_free_commit()
gpio: cdev: don't overwrite the whole flags field when configuring lines
drivers/gpio/gpiolib-cdev.c | 93 +++++++++++++++++++++----------------------
drivers/gpio/gpiolib-shared.c | 5 +--
drivers/gpio/gpiolib.c | 35 ++++++++--------
3 files changed, 65 insertions(+), 68 deletions(-)
---
base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47
change-id: 20261104-gpio-desc-flags-atomic-cc963a1ccfd0
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>