Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit ee0166b

Browse files
warthog618Bartosz Golaszewski
authored andcommitted
gpiolib: cdev: fix uninitialised kfifo
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: 65cff70 ("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>
1 parent 02f6b0e commit ee0166b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

drivers/gpio/gpiolib-cdev.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,8 @@ static int edge_detector_update(struct line *line,
11931193
struct gpio_v2_line_config *lc,
11941194
unsigned int line_idx, u64 edflags)
11951195
{
1196+
u64 eflags;
1197+
int ret;
11961198
u64 active_edflags = READ_ONCE(line->edflags);
11971199
unsigned int debounce_period_us =
11981200
gpio_v2_line_config_debounce_period(lc, line_idx);
@@ -1204,6 +1206,18 @@ static int edge_detector_update(struct line *line,
12041206
/* sw debounced and still will be...*/
12051207
if (debounce_period_us && READ_ONCE(line->sw_debounced)) {
12061208
line_set_debounce_period(line, debounce_period_us);
1209+
/*
1210+
* ensure event fifo is initialised if edge detection
1211+
* is now enabled.
1212+
*/
1213+
eflags = edflags & GPIO_V2_LINE_EDGE_FLAGS;
1214+
if (eflags && !kfifo_initialized(&line->req->events)) {
1215+
ret = kfifo_alloc(&line->req->events,
1216+
line->req->event_buffer_size,
1217+
GFP_KERNEL);
1218+
if (ret)
1219+
return ret;
1220+
}
12071221
return 0;
12081222
}
12091223

0 commit comments

Comments
 (0)