mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] gpiolib: clear the event clock flags when a line is released
@ 2026-10-12 13:49 Adrian Ambrozewicz
       [not found] ` <sashiko-outbox-168236@kernel.org>
  2026-10-19  8:02 ` Bartosz Golaszewski
  0 siblings, 2 replies; 5+ messages in thread
From: Adrian Ambrozewicz @ 2026-10-12 13:49 UTC (permalink / raw)
  To: Bartosz Golaszewski, Linus Walleij
  Cc: Bartosz Golaszewski, Kent Gibson, Dipen Patel, Thierry Reding,
	linux-gpio, linux-kernel

gpiod_free_commit() clears the flags that a request sets on a line, but
not GPIOD_FLAG_EVENT_CLOCK_REALTIME and GPIOD_FLAG_EVENT_CLOCK_HTE,
which gpio_v2_line_config_flags_to_desc_flags() sets from the uAPI v2
line config. Once a line requested with
GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME or
GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE is released, GPIO_V2_GET_LINEINFO_IOCTL
and the line info changed events, the "released" one included, keep
reporting that event clock for the free line:

  GPIO_V2_GET_LINE_IOCTL, line 1, input, event clock realtime:  ok
  close()
  GPIO_V2_GET_LINEINFO_IOCTL, line 1:  input, event clock realtime

The flags are set before edge detection is set up, so a request that
fails in hte_ts_get(), for instance because no HTE provider handles the
line, leaves GPIOD_FLAG_EVENT_CLOCK_HTE behind as well. The next uAPI v2
request rewrites both flags, but requests through uAPI v1, sysfs exports
and in-kernel consumers do not, and the line info then shows the event
clock of an earlier user for them too.

Clear both flags together with the other flags of the request.

Reproduced under QEMU with a test GPIO chip: after a released request
with the realtime event clock, and on a kernel with CONFIG_HTE=y but no
HTE provider after a failed request with the HTE event clock, the line
info of the free line still reports that event clock. With this change
it reports none.

Fixes: 26d060e47e25 ("gpiolib: cdev: allow edge event timestamps to be configured as REALTIME")
Fixes: 2068339a6c35 ("gpiolib: cdev: Add hardware timestamp clock type")
Signed-off-by: Adrian Ambrozewicz <aambrozewicz@nvidia.com>
---
 drivers/gpio/gpiolib.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 772c6f04f489..c6cee872e4ae 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);

base-commit: 72d3fcf802c45d00b300f25b848a93c3a2bd7c7e
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpiolib: clear the event clock flags when a line is released
       [not found] ` <sashiko-outbox-168236@kernel.org>
@ 2026-10-16  7:46   ` Adrian Ambrozewicz
  2026-10-16  9:03     ` Bartosz Golaszewski
  0 siblings, 1 reply; 5+ messages in thread
From: Adrian Ambrozewicz @ 2026-10-16  7:46 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Linus Walleij, Bartosz Golaszewski, Kent Gibson, linux-gpio,
	linux-kernel

On Mon, Oct 12, 2026 at 02:05:49PM +0000, sashiko-bot@kernel.org wrote:
> 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:

This is real, and older than this patch: once the cleared
GPIOD_FLAG_REQUESTED is visible, a new request can set
desc->debounce_period_us in edge_detector_setup() before the old one
resets it to 0, and the debounce code reads the period from there.

I'll send a fix with v2 of the chip-removal series, which touches the
same function: reset the period first, then write the flags with
release ordering, pairing with the test_and_set_bit() in
gpiod_request_commit(), so that a new owner sees the reset. The
RELEASED notification can still arrive after the new request's
REQUESTED one. Moving it before the flags update would report the line
as still requested in the RELEASED event, so the fix will describe
that rather than reorder it.

Adrian

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpiolib: clear the event clock flags when a line is released
  2026-10-16  7:46   ` Adrian Ambrozewicz
@ 2026-10-16  9:03     ` Bartosz Golaszewski
  2026-10-16  9:39       ` Adrian Ambrozewicz
  0 siblings, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2026-10-16  9:03 UTC (permalink / raw)
  To: Adrian Ambrozewicz
  Cc: Linus Walleij, Bartosz Golaszewski, Kent Gibson, linux-gpio,
	linux-kernel, Bartosz Golaszewski

On Fri, 16 Oct 2026 09:46:57 +0200, Adrian Ambrozewicz
<aambrozewicz@nvidia.com> said:
> On Mon, Oct 12, 2026 at 02:05:49PM +0000, sashiko-bot@kernel.org wrote:
>> 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:
>
> This is real, and older than this patch: once the cleared
> GPIOD_FLAG_REQUESTED is visible, a new request can set
> desc->debounce_period_us in edge_detector_setup() before the old one
> resets it to 0, and the debounce code reads the period from there.
>
> I'll send a fix with v2 of the chip-removal series, which touches the
> same function: reset the period first, then write the flags with
> release ordering, pairing with the test_and_set_bit() in
> gpiod_request_commit(), so that a new owner sees the reset. The
> RELEASED notification can still arrive after the new request's
> REQUESTED one. Moving it before the flags update would report the line
> as still requested in the RELEASED event, so the fix will describe
> that rather than reorder it.
>

Will you resend this together with that v2? Or should I take it independently?

Bartosz

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpiolib: clear the event clock flags when a line is released
  2026-10-16  9:03     ` Bartosz Golaszewski
@ 2026-10-16  9:39       ` Adrian Ambrozewicz
  0 siblings, 0 replies; 5+ messages in thread
From: Adrian Ambrozewicz @ 2026-10-16  9:39 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Linus Walleij, Bartosz Golaszewski, Kent Gibson, linux-gpio,
	linux-kernel

On Fri, Oct 16, 2026 at 04:03:24AM -0500, Bartosz Golaszewski wrote:
> Will you resend this together with that v2? Or should I take it independently?

Please take it independently. It doesn't depend on the removal series
and still applies to gpio/for-current and gpio/for-next.

The debounce fix didn't go into v2 in the end: Kent asked to keep fixes
for existing problems out of the removal series, and the fix builds on
the gpiod_free_commit() rework in patch 2. I'll send it once the series
is applied.

Adrian

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpiolib: clear the event clock flags when a line is released
  2026-10-12 13:49 [PATCH] gpiolib: clear the event clock flags when a line is released Adrian Ambrozewicz
       [not found] ` <sashiko-outbox-168236@kernel.org>
@ 2026-10-19  8:02 ` Bartosz Golaszewski
  1 sibling, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2026-10-19  8:02 UTC (permalink / raw)
  To: Bartosz Golaszewski, Linus Walleij, Adrian Ambrozewicz
  Cc: Bartosz Golaszewski, Kent Gibson, Dipen Patel, Thierry Reding,
	linux-gpio, linux-kernel


On Mon, 12 Oct 2026 16:49:45 +0300, Adrian Ambrozewicz wrote:
> gpiod_free_commit() clears the flags that a request sets on a line, but
> not GPIOD_FLAG_EVENT_CLOCK_REALTIME and GPIOD_FLAG_EVENT_CLOCK_HTE,
> which gpio_v2_line_config_flags_to_desc_flags() sets from the uAPI v2
> line config. Once a line requested with
> GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME or
> GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE is released, GPIO_V2_GET_LINEINFO_IOCTL
> and the line info changed events, the "released" one included, keep
> reporting that event clock for the free line:
> 
> [...]

Applied, thanks!

[1/1] gpiolib: clear the event clock flags when a line is released
      https://git.kernel.org/brgl/c/d35f61581ee67f8d4d58c325bac813cea528b6b9

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-10-19  8:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-12 13:49 [PATCH] gpiolib: clear the event clock flags when a line is released Adrian Ambrozewicz
     [not found] ` <sashiko-outbox-168236@kernel.org>
2026-10-16  7:46   ` Adrian Ambrozewicz
2026-10-16  9:03     ` Bartosz Golaszewski
2026-10-16  9:39       ` Adrian Ambrozewicz
2026-10-19  8:02 ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®