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 <warthog618@gmail.com> Link: https://lore.kernel.org/r/20240529131953.195777-3-warthog618@gmail.com Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
This commit is contained in:
parent
35d848e7a1
commit
4ce5ca654a
@ -1128,6 +1128,14 @@ static void edge_detector_stop(struct line *line)
|
|||||||
/* do not change line->level - see comment in debounced_value() */
|
/* do not change line->level - see comment in debounced_value() */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int edge_detector_fifo_init(struct linereq *req)
|
||||||
|
{
|
||||||
|
if (kfifo_initialized(&req->events))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return kfifo_alloc(&req->events, req->event_buffer_size, GFP_KERNEL);
|
||||||
|
}
|
||||||
|
|
||||||
static int edge_detector_setup(struct line *line,
|
static int edge_detector_setup(struct line *line,
|
||||||
struct gpio_v2_line_config *lc,
|
struct gpio_v2_line_config *lc,
|
||||||
unsigned int line_idx, u64 edflags)
|
unsigned int line_idx, u64 edflags)
|
||||||
@ -1139,9 +1147,8 @@ static int edge_detector_setup(struct line *line,
|
|||||||
char *label;
|
char *label;
|
||||||
|
|
||||||
eflags = edflags & GPIO_V2_LINE_EDGE_FLAGS;
|
eflags = edflags & GPIO_V2_LINE_EDGE_FLAGS;
|
||||||
if (eflags && !kfifo_initialized(&line->req->events)) {
|
if (eflags) {
|
||||||
ret = kfifo_alloc(&line->req->events,
|
ret = edge_detector_fifo_init(line->req);
|
||||||
line->req->event_buffer_size, GFP_KERNEL);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -1193,8 +1200,6 @@ static int edge_detector_update(struct line *line,
|
|||||||
struct gpio_v2_line_config *lc,
|
struct gpio_v2_line_config *lc,
|
||||||
unsigned int line_idx, u64 edflags)
|
unsigned int line_idx, u64 edflags)
|
||||||
{
|
{
|
||||||
u64 eflags;
|
|
||||||
int ret;
|
|
||||||
u64 active_edflags = READ_ONCE(line->edflags);
|
u64 active_edflags = READ_ONCE(line->edflags);
|
||||||
unsigned int debounce_period_us =
|
unsigned int debounce_period_us =
|
||||||
gpio_v2_line_config_debounce_period(lc, line_idx);
|
gpio_v2_line_config_debounce_period(lc, line_idx);
|
||||||
@ -1210,14 +1215,9 @@ static int edge_detector_update(struct line *line,
|
|||||||
* ensure event fifo is initialised if edge detection
|
* ensure event fifo is initialised if edge detection
|
||||||
* is now enabled.
|
* is now enabled.
|
||||||
*/
|
*/
|
||||||
eflags = edflags & GPIO_V2_LINE_EDGE_FLAGS;
|
if (edflags & GPIO_V2_LINE_EDGE_FLAGS)
|
||||||
if (eflags && !kfifo_initialized(&line->req->events)) {
|
return edge_detector_fifo_init(line->req);
|
||||||
ret = kfifo_alloc(&line->req->events,
|
|
||||||
line->req->event_buffer_size,
|
|
||||||
GFP_KERNEL);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user