public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Input: avoid calling input_set_abs_val() in the event handling core
@ 2023-05-02  1:01 Dmitry Torokhov
  2023-05-02  6:05 ` Peter Hutterer
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Torokhov @ 2023-05-02  1:01 UTC (permalink / raw)
  To: linux-input; +Cc: Teng Qi, linux-kernel

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 <starmiku1207184332@gmail.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/input.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/input/input.c b/drivers/input/input.c
index 37e876d45eb9..f791d14ecf23 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -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;
 
@@ -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
@@ -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;
 	}
 
-- 
2.40.1.495.gc816e09b53d-goog


-- 
Dmitry

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Input: avoid calling input_set_abs_val() in the event handling core
  2023-05-02  1:01 [PATCH] Input: avoid calling input_set_abs_val() in the event handling core Dmitry Torokhov
@ 2023-05-02  6:05 ` Peter Hutterer
  2023-05-02 20:21   ` Dmitry Torokhov
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Hutterer @ 2023-05-02  6:05 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, Teng Qi, linux-kernel

On Mon, May 01, 2023 at 06:01:19PM -0700, Dmitry Torokhov wrote:
> 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 <starmiku1207184332@gmail.com>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>

If git grep is to be believed, this is the only use of
input_abs_set_val. Maybe removing that function is an option?

Are there external drivers that rely on this (instead of sending an
event)?

Cheers,
  Peter

> ---
>  drivers/input/input.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/input/input.c b/drivers/input/input.c
> index 37e876d45eb9..f791d14ecf23 100644
> --- a/drivers/input/input.c
> +++ b/drivers/input/input.c
> @@ -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;
>  
> @@ -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
> @@ -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;
>  	}
>  
> -- 
> 2.40.1.495.gc816e09b53d-goog
> 
> 
> -- 
> Dmitry

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Input: avoid calling input_set_abs_val() in the event handling core
  2023-05-02  6:05 ` Peter Hutterer
@ 2023-05-02 20:21   ` Dmitry Torokhov
  0 siblings, 0 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2023-05-02 20:21 UTC (permalink / raw)
  To: Peter Hutterer; +Cc: linux-input, Teng Qi, linux-kernel

On Tue, May 02, 2023 at 04:05:31PM +1000, Peter Hutterer wrote:
> On Mon, May 01, 2023 at 06:01:19PM -0700, Dmitry Torokhov wrote:
> > 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 <starmiku1207184332@gmail.com>
> > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> 
> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>

Thanks for the review.

> 
> If git grep is to be believed, this is the only use of
> input_abs_set_val. Maybe removing that function is an option?

We generate input_abs_[get|set]_<item>() accessors and setters, and
there is a couple of users of input_abs_get_val() in the code, so
dropping just input_abs_set_val() is kind of hard. It might be useful
elsewhere although I have no idea if anyone is actually using it
anywhere...

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-05-02 20:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-02  1:01 [PATCH] Input: avoid calling input_set_abs_val() in the event handling core Dmitry Torokhov
2023-05-02  6:05 ` Peter Hutterer
2023-05-02 20:21   ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox