From: sashiko-bot@kernel.org
To: "Adrian Ambrozewicz" <aambrozewicz@nvidia.com>
Cc: linux-gpio@vger.kernel.org
Subject: Re: [PATCH] gpiolib: clear the event clock flags when a line is released
Date: Mon, 12 Oct 2026 14:05:49 +0000 [thread overview]
Message-ID: <sashiko-outbox-168236@kernel.org> (raw)
In-Reply-To: <20261012-gpiolib-event-clock-v1-1-aambrozewicz@nvidia.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] gpio: data race in gpiod_free_commit() causes debounce corruption
--
commit 9516d6cf1c2a072b1bec8e797ac66548d0323b06
Author: Adrian Ambrozewicz <aambrozewicz@nvidia.com>
gpiolib: clear the event clock flags when a line is released
This commit ensures that the GPIOD_FLAG_EVENT_CLOCK_REALTIME and
GPIOD_FLAG_EVENT_CLOCK_HTE flags are cleared when a GPIO line is released.
It modifies gpiod_free_commit() to clear these flags alongside others so
that they do not leak into the line info for a freed line.
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 772c6f04f489b..c6cee872e4ae5 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -2679,6 +2679,8 @@ void gpiod_free_commit(struct gpio_desc *desc)
> clear_bit(GPIOD_FLAG_BIAS_DISABLE, &flags);
> clear_bit(GPIOD_FLAG_EDGE_RISING, &flags);
> clear_bit(GPIOD_FLAG_EDGE_FALLING, &flags);
> + clear_bit(GPIOD_FLAG_EVENT_CLOCK_REALTIME, &flags);
> + clear_bit(GPIOD_FLAG_EVENT_CLOCK_HTE, &flags);
> clear_bit(GPIOD_FLAG_IS_HOGGED, &flags);
> #ifdef CONFIG_OF_DYNAMIC
> WRITE_ONCE(desc->hog, NULL);
[Severity: High]
Does this code cause debounce corruption by clearing ownership too early?
In gpiod_free_commit(), the ownership synchronization token
(GPIOD_FLAG_REQUESTED) is cleared in desc->flags via a WRITE_ONCE() before
the function finishes cleaning up ancillary state (debounce_period_us) and
emitting the GPIO_V2_LINE_CHANGED_RELEASED notification:
drivers/gpio/gpiolib.c:gpiod_free_commit() {
...
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);
...
}
This allows a concurrent request (e.g., from GPIO_V2_GET_LINE_IOCTL via
linereq_create()) to successfully acquire the GPIO line:
drivers/gpio/gpiolib.c:gpiod_request_commit() {
...
if (test_and_set_bit(GPIOD_FLAG_REQUESTED, &desc->flags))
return -EBUSY;
...
}
It can then configure a new debounce_period_us:
drivers/gpio/gpiolib-cdev.c:edge_detector_setup() {
...
WRITE_ONCE(line->desc->debounce_period_us, debounce_period_us);
...
}
The original freeing thread then resumes and overwrites the newly requested
line's debounce_period_us with 0. This completely breaks software debouncing,
causing a 0-delay software debounce that will trigger its delayed work
immediately on every hardware edge. This could lead to an interrupt storm
and CPU soft lockup.
Additionally, this sends an out-of-order RELEASED notification to userspace
for a line that is currently fully requested and active.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261012-gpiolib-event-clock-v1-1-aambrozewicz@nvidia.com?part=1
prev parent reply other threads:[~2026-10-12 14:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-12 13:49 [PATCH] gpiolib: clear the event clock flags when a line is released Adrian Ambrozewicz
2026-10-12 14:05 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-168236@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=aambrozewicz@nvidia.com \
--cc=linux-gpio@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox