diff mbox series

[v2,1/5] Input: Set EV_ABS in dev->evbit even if input_alloc_absinfo() fails

Message ID 20220131143539.109142-1-hdegoede@redhat.com (mailing list archive)
State Accepted
Commit 3f9ed5c2fe36794c1b11697bbbc6c8ec82a7d3dc
Headers show
Series [v2,1/5] Input: Set EV_ABS in dev->evbit even if input_alloc_absinfo() fails | expand

Commit Message

Hans de Goede Jan. 31, 2022, 2:35 p.m. UTC
The input core's error handling for input_alloc_absinfo() failures
is based on ignoring the error until input_register_device() runs
and then checks for the failure like this:

        if (test_bit(EV_ABS, dev->evbit) && !dev->absinfo) {
                dev_err(&dev->dev, ...);
                return -EINVAL;
        }

This relies on EV_ABS actually getting set in dev->evbit even
if input_alloc_absinfo() fails, change input_set_abs_params() and
input_set_capability() to actually adhere to this.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v2:
- New patch in v2 of this patch-set
---
 drivers/input/input.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Comments

Dmitry Torokhov March 1, 2022, 7:03 a.m. UTC | #1
Hi Hans,

On Mon, Jan 31, 2022 at 03:35:35PM +0100, Hans de Goede wrote:
> The input core's error handling for input_alloc_absinfo() failures

The original idea was actually to catch cases where ABS axis was set up
without calling input_set_capability() or input_set_abs_info(), but
great idea to also catch allocation failures.

> is based on ignoring the error until input_register_device() runs
> and then checks for the failure like this:
> 
>         if (test_bit(EV_ABS, dev->evbit) && !dev->absinfo) {
>                 dev_err(&dev->dev, ...);
>                 return -EINVAL;
>         }
> 
> This relies on EV_ABS actually getting set in dev->evbit even
> if input_alloc_absinfo() fails, change input_set_abs_params() and
> input_set_capability() to actually adhere to this.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Applied, thank you.
diff mbox series

Patch

diff --git a/drivers/input/input.c b/drivers/input/input.c
index ccaeb2426385..3a5156012fb8 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -511,6 +511,9 @@  void input_set_abs_params(struct input_dev *dev, unsigned int axis,
 {
 	struct input_absinfo *absinfo;
 
+	__set_bit(EV_ABS, dev->evbit);
+	__set_bit(axis, dev->absbit);
+
 	input_alloc_absinfo(dev);
 	if (!dev->absinfo)
 		return;
@@ -520,9 +523,6 @@  void input_set_abs_params(struct input_dev *dev, unsigned int axis,
 	absinfo->maximum = max;
 	absinfo->fuzz = fuzz;
 	absinfo->flat = flat;
-
-	__set_bit(EV_ABS, dev->evbit);
-	__set_bit(axis, dev->absbit);
 }
 EXPORT_SYMBOL(input_set_abs_params);
 
@@ -2085,9 +2085,6 @@  void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int
 
 	case EV_ABS:
 		input_alloc_absinfo(dev);
-		if (!dev->absinfo)
-			return;
-
 		__set_bit(code, dev->absbit);
 		break;