Skip to content

Commit

Permalink
Input: avoid calling input_set_abs_val() in the event handling core
Browse files Browse the repository at this point in the history
input_abs_set_val() can nominally call input_alloc_absinfo() which may
allocate memory with GFP_KERNEL flag. This does not happen when
input_abs_set_val() is called by the input core to set current MT slot when
handling a new input event, but it trips certain static analyzers.

Rearrange the code to access the relevant structures directly.

Reported-by: Teng Qi <[email protected]>
Reviewed-by: Peter Hutterer <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Dmitry Torokhov <[email protected]>
  • Loading branch information
dtor committed May 2, 2023
1 parent e0f41f8 commit 3516fa1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ static int input_handle_abs_event(struct input_dev *dev,
unsigned int code, int *pval)
{
struct input_mt *mt = dev->mt;
bool is_new_slot = false;
bool is_mt_event;
int *pold;

Expand All @@ -210,6 +211,7 @@ static int input_handle_abs_event(struct input_dev *dev,
pold = &dev->absinfo[code].value;
} else if (mt) {
pold = &mt->slots[mt->slot].abs[code - ABS_MT_FIRST];
is_new_slot = mt->slot != dev->absinfo[ABS_MT_SLOT].value;
} else {
/*
* Bypass filtering for multi-touch events when
Expand All @@ -228,8 +230,8 @@ static int input_handle_abs_event(struct input_dev *dev,
}

/* Flush pending "slot" event */
if (is_mt_event && mt && mt->slot != input_abs_get_val(dev, ABS_MT_SLOT)) {
input_abs_set_val(dev, ABS_MT_SLOT, mt->slot);
if (is_new_slot) {
dev->absinfo[ABS_MT_SLOT].value = mt->slot;
return INPUT_PASS_TO_HANDLERS | INPUT_SLOT;
}

Expand Down

0 comments on commit 3516fa1

Please sign in to comment.