* [PATCH 5.15.y] gpiolib: cdev: fix uninitialised kfifo
@ 2026-04-09 7:22 Robert Garcia
2026-04-13 4:14 ` Sasha Levin
0 siblings, 1 reply; 2+ messages in thread
From: Robert Garcia @ 2026-04-09 7:22 UTC (permalink / raw)
To: stable, Kent Gibson
Cc: Bartosz Golaszewski, Robert Garcia, Linus Walleij,
Bartosz Golaszewski, linux-gpio, linux-kernel
From: Kent Gibson <warthog618@gmail.com>
[ Upstream commit ee0166b637a5e376118e9659e5b4148080f1d27e ]
If a line is requested with debounce, and that results in debouncing
in software, and the line is subsequently reconfigured to enable edge
detection then the allocation of the kfifo to contain edge events is
overlooked. This results in events being written to and read from an
uninitialised kfifo. Read events are returned to userspace.
Initialise the kfifo in the case where the software debounce is
already active.
Fixes: 65cff7046406 ("gpiolib: cdev: support setting debounce")
Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240510065342.36191-1-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Robert Garcia <rob_garcia@163.com>
---
drivers/gpio/gpiolib-cdev.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index 3cd19ab1fc2a..d4b221c90bb2 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -896,6 +896,7 @@ static int edge_detector_update(struct line *line,
unsigned int line_idx,
u64 eflags, bool polarity_change)
{
+ int ret;
unsigned int debounce_period_us =
gpio_v2_line_config_debounce_period(lc, line_idx);
@@ -907,6 +908,18 @@ static int edge_detector_update(struct line *line,
if (debounce_period_us && READ_ONCE(line->sw_debounced)) {
WRITE_ONCE(line->eflags, eflags);
WRITE_ONCE(line->desc->debounce_period_us, debounce_period_us);
+ /*
+ * ensure event fifo is initialised if edge detection
+ * is now enabled.
+ */
+ eflags = eflags & GPIO_V2_LINE_EDGE_FLAGS;
+ if (eflags && !kfifo_initialized(&line->req->events)) {
+ ret = kfifo_alloc(&line->req->events,
+ line->req->event_buffer_size,
+ GFP_KERNEL);
+ if (ret)
+ return ret;
+ }
return 0;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 5.15.y] gpiolib: cdev: fix uninitialised kfifo
2026-04-09 7:22 [PATCH 5.15.y] gpiolib: cdev: fix uninitialised kfifo Robert Garcia
@ 2026-04-13 4:14 ` Sasha Levin
0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2026-04-13 4:14 UTC (permalink / raw)
To: Robert Garcia; +Cc: Sasha Levin, stable, Kent Gibson, Bartosz Golaszewski
> [PATCH 5.15.y] gpiolib: cdev: fix uninitialised kfifo
Queued for 5.15, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-13 4:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-09 7:22 [PATCH 5.15.y] gpiolib: cdev: fix uninitialised kfifo Robert Garcia
2026-04-13 4:14 ` Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox