Skip to content

Commit 4ce5ca6

Browse files
warthog618Bartosz Golaszewski
authored andcommitted
gpiolib: cdev: Refactor allocation of linereq events kfifo
The allocation of the linereq events kfifo is performed in two separate places. Add a helper function to remove the duplication. Signed-off-by: Kent Gibson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 35d848e commit 4ce5ca6

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

drivers/gpio/gpiolib-cdev.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,14 @@ static void edge_detector_stop(struct line *line)
11281128
/* do not change line->level - see comment in debounced_value() */
11291129
}
11301130

1131+
static int edge_detector_fifo_init(struct linereq *req)
1132+
{
1133+
if (kfifo_initialized(&req->events))
1134+
return 0;
1135+
1136+
return kfifo_alloc(&req->events, req->event_buffer_size, GFP_KERNEL);
1137+
}
1138+
11311139
static int edge_detector_setup(struct line *line,
11321140
struct gpio_v2_line_config *lc,
11331141
unsigned int line_idx, u64 edflags)
@@ -1139,9 +1147,8 @@ static int edge_detector_setup(struct line *line,
11391147
char *label;
11401148

11411149
eflags = edflags & GPIO_V2_LINE_EDGE_FLAGS;
1142-
if (eflags && !kfifo_initialized(&line->req->events)) {
1143-
ret = kfifo_alloc(&line->req->events,
1144-
line->req->event_buffer_size, GFP_KERNEL);
1150+
if (eflags) {
1151+
ret = edge_detector_fifo_init(line->req);
11451152
if (ret)
11461153
return ret;
11471154
}
@@ -1193,8 +1200,6 @@ static int edge_detector_update(struct line *line,
11931200
struct gpio_v2_line_config *lc,
11941201
unsigned int line_idx, u64 edflags)
11951202
{
1196-
u64 eflags;
1197-
int ret;
11981203
u64 active_edflags = READ_ONCE(line->edflags);
11991204
unsigned int debounce_period_us =
12001205
gpio_v2_line_config_debounce_period(lc, line_idx);
@@ -1210,14 +1215,9 @@ static int edge_detector_update(struct line *line,
12101215
* ensure event fifo is initialised if edge detection
12111216
* is now enabled.
12121217
*/
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-
}
1218+
if (edflags & GPIO_V2_LINE_EDGE_FLAGS)
1219+
return edge_detector_fifo_init(line->req);
1220+
12211221
return 0;
12221222
}
12231223

0 commit comments

Comments
 (0)