* [PATCH v2] HID: playstation: Center initial joystick axes to prevent spurious events
@ 2025-11-11 23:45 Siarhei Vishniakou
2025-12-01 18:30 ` Siarhei Vishniakou
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Siarhei Vishniakou @ 2025-11-11 23:45 UTC (permalink / raw)
To: Jiri Kosina, Benjamin Tissoires, Roderick Colenbrander,
linux-input, linux-kernel
Cc: Siarhei Vishniakou
When a new PlayStation gamepad (DualShock 4 or DualSense) is initialized,
the input subsystem sets the default value for its absolute axes (e.g.,
ABS_X, ABS_Y) to 0.
However, the hardware's actual neutral/resting state for these joysticks
is 128 (0x80). This creates a mismatch.
When the first HID report arrives from the device, the driver sees the
resting value of 128. The kernel compares this to its initial state of 0
and incorrectly interprets this as a delta (0 -> 128). Consequently, it
generates EV_ABS events for this initial, non-existent movement.
This behavior can fail userspace 'sanity check' tests (e.g., in
Android CTS) that correctly assert no motion events should be generated
from a device that is already at rest.
This patch fixes the issue by explicitly setting the initial value of the
main joystick axes (e.g., ABS_X, ABS_Y, ABS_RX, ABS_RY) to 128 (0x80)
in the common ps_gamepad_create() function.
This aligns the kernel's initial state with the hardware's expected
neutral state, ensuring that the first report (at 128) produces no
delta and thus, no spurious event.
Signed-off-by: Siarhei Vishniakou <svv@google.com>
---
drivers/hid/hid-playstation.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index 1468fb11e39d..a145b5ea4405 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -718,11 +718,16 @@ static struct input_dev *ps_gamepad_create(struct hid_device *hdev,
if (IS_ERR(gamepad))
return ERR_CAST(gamepad);
+ /* Set initial resting state for joysticks to 128 (center) */
input_set_abs_params(gamepad, ABS_X, 0, 255, 0, 0);
+ gamepad->absinfo[ABS_X].value = 128;
input_set_abs_params(gamepad, ABS_Y, 0, 255, 0, 0);
+ gamepad->absinfo[ABS_Y].value = 128;
input_set_abs_params(gamepad, ABS_Z, 0, 255, 0, 0);
input_set_abs_params(gamepad, ABS_RX, 0, 255, 0, 0);
+ gamepad->absinfo[ABS_RX].value = 128;
input_set_abs_params(gamepad, ABS_RY, 0, 255, 0, 0);
+ gamepad->absinfo[ABS_RY].value = 128;
input_set_abs_params(gamepad, ABS_RZ, 0, 255, 0, 0);
input_set_abs_params(gamepad, ABS_HAT0X, -1, 1, 0, 0);
--
2.51.2.1041.gc1ab5b90ca-goog
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] HID: playstation: Center initial joystick axes to prevent spurious events
2025-11-11 23:45 [PATCH v2] HID: playstation: Center initial joystick axes to prevent spurious events Siarhei Vishniakou
@ 2025-12-01 18:30 ` Siarhei Vishniakou
2025-12-02 8:25 ` Benjamin Tissoires
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Siarhei Vishniakou @ 2025-12-01 18:30 UTC (permalink / raw)
To: Jiri Kosina, Benjamin Tissoires, Roderick Colenbrander,
linux-input, linux-kernel
вт, 11 нояб. 2025 г. в 15:45, Siarhei Vishniakou <svv@google.com>:
>
> When a new PlayStation gamepad (DualShock 4 or DualSense) is initialized,
> the input subsystem sets the default value for its absolute axes (e.g.,
> ABS_X, ABS_Y) to 0.
>
> However, the hardware's actual neutral/resting state for these joysticks
> is 128 (0x80). This creates a mismatch.
>
> When the first HID report arrives from the device, the driver sees the
> resting value of 128. The kernel compares this to its initial state of 0
> and incorrectly interprets this as a delta (0 -> 128). Consequently, it
> generates EV_ABS events for this initial, non-existent movement.
>
> This behavior can fail userspace 'sanity check' tests (e.g., in
> Android CTS) that correctly assert no motion events should be generated
> from a device that is already at rest.
>
> This patch fixes the issue by explicitly setting the initial value of the
> main joystick axes (e.g., ABS_X, ABS_Y, ABS_RX, ABS_RY) to 128 (0x80)
> in the common ps_gamepad_create() function.
>
> This aligns the kernel's initial state with the hardware's expected
> neutral state, ensuring that the first report (at 128) produces no
> delta and thus, no spurious event.
>
> Signed-off-by: Siarhei Vishniakou <svv@google.com>
> ---
> drivers/hid/hid-playstation.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
> index 1468fb11e39d..a145b5ea4405 100644
> --- a/drivers/hid/hid-playstation.c
> +++ b/drivers/hid/hid-playstation.c
> @@ -718,11 +718,16 @@ static struct input_dev *ps_gamepad_create(struct hid_device *hdev,
> if (IS_ERR(gamepad))
> return ERR_CAST(gamepad);
>
> + /* Set initial resting state for joysticks to 128 (center) */
> input_set_abs_params(gamepad, ABS_X, 0, 255, 0, 0);
> + gamepad->absinfo[ABS_X].value = 128;
> input_set_abs_params(gamepad, ABS_Y, 0, 255, 0, 0);
> + gamepad->absinfo[ABS_Y].value = 128;
> input_set_abs_params(gamepad, ABS_Z, 0, 255, 0, 0);
> input_set_abs_params(gamepad, ABS_RX, 0, 255, 0, 0);
> + gamepad->absinfo[ABS_RX].value = 128;
> input_set_abs_params(gamepad, ABS_RY, 0, 255, 0, 0);
> + gamepad->absinfo[ABS_RY].value = 128;
> input_set_abs_params(gamepad, ABS_RZ, 0, 255, 0, 0);
>
> input_set_abs_params(gamepad, ABS_HAT0X, -1, 1, 0, 0);
> --
> 2.51.2.1041.gc1ab5b90ca-goog
>
Hey Jiri,
Do you mind taking a look at this one?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] HID: playstation: Center initial joystick axes to prevent spurious events
2025-11-11 23:45 [PATCH v2] HID: playstation: Center initial joystick axes to prevent spurious events Siarhei Vishniakou
2025-12-01 18:30 ` Siarhei Vishniakou
@ 2025-12-02 8:25 ` Benjamin Tissoires
2025-12-19 13:05 ` Benjamin Tissoires
2026-02-24 21:10 ` Guenter Roeck
3 siblings, 0 replies; 7+ messages in thread
From: Benjamin Tissoires @ 2025-12-02 8:25 UTC (permalink / raw)
To: Siarhei Vishniakou
Cc: Jiri Kosina, Roderick Colenbrander, linux-input, linux-kernel
On Nov 11 2025, Siarhei Vishniakou wrote:
> When a new PlayStation gamepad (DualShock 4 or DualSense) is initialized,
> the input subsystem sets the default value for its absolute axes (e.g.,
> ABS_X, ABS_Y) to 0.
>
> However, the hardware's actual neutral/resting state for these joysticks
> is 128 (0x80). This creates a mismatch.
>
> When the first HID report arrives from the device, the driver sees the
> resting value of 128. The kernel compares this to its initial state of 0
> and incorrectly interprets this as a delta (0 -> 128). Consequently, it
> generates EV_ABS events for this initial, non-existent movement.
>
> This behavior can fail userspace 'sanity check' tests (e.g., in
> Android CTS) that correctly assert no motion events should be generated
> from a device that is already at rest.
>
> This patch fixes the issue by explicitly setting the initial value of the
> main joystick axes (e.g., ABS_X, ABS_Y, ABS_RX, ABS_RY) to 128 (0x80)
> in the common ps_gamepad_create() function.
>
> This aligns the kernel's initial state with the hardware's expected
> neutral state, ensuring that the first report (at 128) produces no
> delta and thus, no spurious event.
>
> Signed-off-by: Siarhei Vishniakou <svv@google.com>
Reviewed-by: Benjamin Tissoires <bentiss@kernel.org>
FWIW, we are in the merge window for 6.19, so unless we sneak this one
in an early rc (which should be doable), I do not think we'll take this
one right now when we need to send the PR for 6.19 as we speak.
Cheers,
Benjamin
> ---
> drivers/hid/hid-playstation.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
> index 1468fb11e39d..a145b5ea4405 100644
> --- a/drivers/hid/hid-playstation.c
> +++ b/drivers/hid/hid-playstation.c
> @@ -718,11 +718,16 @@ static struct input_dev *ps_gamepad_create(struct hid_device *hdev,
> if (IS_ERR(gamepad))
> return ERR_CAST(gamepad);
>
> + /* Set initial resting state for joysticks to 128 (center) */
> input_set_abs_params(gamepad, ABS_X, 0, 255, 0, 0);
> + gamepad->absinfo[ABS_X].value = 128;
> input_set_abs_params(gamepad, ABS_Y, 0, 255, 0, 0);
> + gamepad->absinfo[ABS_Y].value = 128;
> input_set_abs_params(gamepad, ABS_Z, 0, 255, 0, 0);
> input_set_abs_params(gamepad, ABS_RX, 0, 255, 0, 0);
> + gamepad->absinfo[ABS_RX].value = 128;
> input_set_abs_params(gamepad, ABS_RY, 0, 255, 0, 0);
> + gamepad->absinfo[ABS_RY].value = 128;
> input_set_abs_params(gamepad, ABS_RZ, 0, 255, 0, 0);
>
> input_set_abs_params(gamepad, ABS_HAT0X, -1, 1, 0, 0);
> --
> 2.51.2.1041.gc1ab5b90ca-goog
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] HID: playstation: Center initial joystick axes to prevent spurious events
2025-11-11 23:45 [PATCH v2] HID: playstation: Center initial joystick axes to prevent spurious events Siarhei Vishniakou
2025-12-01 18:30 ` Siarhei Vishniakou
2025-12-02 8:25 ` Benjamin Tissoires
@ 2025-12-19 13:05 ` Benjamin Tissoires
2026-02-24 21:10 ` Guenter Roeck
3 siblings, 0 replies; 7+ messages in thread
From: Benjamin Tissoires @ 2025-12-19 13:05 UTC (permalink / raw)
To: Jiri Kosina, Roderick Colenbrander, linux-input, linux-kernel,
Siarhei Vishniakou
On Tue, 11 Nov 2025 15:45:19 -0800, Siarhei Vishniakou wrote:
> When a new PlayStation gamepad (DualShock 4 or DualSense) is initialized,
> the input subsystem sets the default value for its absolute axes (e.g.,
> ABS_X, ABS_Y) to 0.
>
> However, the hardware's actual neutral/resting state for these joysticks
> is 128 (0x80). This creates a mismatch.
>
> [...]
Applied to hid/hid.git (for-6.19/upstream-fixes), thanks!
[1/1] HID: playstation: Center initial joystick axes to prevent spurious events
https://git.kernel.org/hid/hid/c/e9143268d259
Cheers,
--
Benjamin Tissoires <bentiss@kernel.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] HID: playstation: Center initial joystick axes to prevent spurious events
2025-11-11 23:45 [PATCH v2] HID: playstation: Center initial joystick axes to prevent spurious events Siarhei Vishniakou
` (2 preceding siblings ...)
2025-12-19 13:05 ` Benjamin Tissoires
@ 2026-02-24 21:10 ` Guenter Roeck
2026-02-24 22:44 ` Siarhei Vishniakou
3 siblings, 1 reply; 7+ messages in thread
From: Guenter Roeck @ 2026-02-24 21:10 UTC (permalink / raw)
To: Siarhei Vishniakou
Cc: Jiri Kosina, Benjamin Tissoires, Roderick Colenbrander,
linux-input, linux-kernel
On Tue, Nov 11, 2025 at 03:45:19PM -0800, Siarhei Vishniakou wrote:
> When a new PlayStation gamepad (DualShock 4 or DualSense) is initialized,
> the input subsystem sets the default value for its absolute axes (e.g.,
> ABS_X, ABS_Y) to 0.
>
> However, the hardware's actual neutral/resting state for these joysticks
> is 128 (0x80). This creates a mismatch.
>
> When the first HID report arrives from the device, the driver sees the
> resting value of 128. The kernel compares this to its initial state of 0
> and incorrectly interprets this as a delta (0 -> 128). Consequently, it
> generates EV_ABS events for this initial, non-existent movement.
>
> This behavior can fail userspace 'sanity check' tests (e.g., in
> Android CTS) that correctly assert no motion events should be generated
> from a device that is already at rest.
>
> This patch fixes the issue by explicitly setting the initial value of the
> main joystick axes (e.g., ABS_X, ABS_Y, ABS_RX, ABS_RY) to 128 (0x80)
> in the common ps_gamepad_create() function.
>
> This aligns the kernel's initial state with the hardware's expected
> neutral state, ensuring that the first report (at 128) produces no
> delta and thus, no spurious event.
>
> Signed-off-by: Siarhei Vishniakou <svv@google.com>
> Reviewed-by: Benjamin Tissoires <bentiss@kernel.org>
> ---
> drivers/hid/hid-playstation.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
> index 1468fb11e39d..a145b5ea4405 100644
> --- a/drivers/hid/hid-playstation.c
> +++ b/drivers/hid/hid-playstation.c
> @@ -718,11 +718,16 @@ static struct input_dev *ps_gamepad_create(struct hid_device *hdev,
> if (IS_ERR(gamepad))
> return ERR_CAST(gamepad);
>
> + /* Set initial resting state for joysticks to 128 (center) */
> input_set_abs_params(gamepad, ABS_X, 0, 255, 0, 0);
> + gamepad->absinfo[ABS_X].value = 128;
input_set_abs_params() can fail to allocate absinfo. If that happens,
this will crash. AI suggests setting the value with input_abs_set_val()
to ensure that the value is checked before dereferencing.
Guenter
> input_set_abs_params(gamepad, ABS_Y, 0, 255, 0, 0);
> + gamepad->absinfo[ABS_Y].value = 128;
> input_set_abs_params(gamepad, ABS_Z, 0, 255, 0, 0);
> input_set_abs_params(gamepad, ABS_RX, 0, 255, 0, 0);
> + gamepad->absinfo[ABS_RX].value = 128;
> input_set_abs_params(gamepad, ABS_RY, 0, 255, 0, 0);
> + gamepad->absinfo[ABS_RY].value = 128;
> input_set_abs_params(gamepad, ABS_RZ, 0, 255, 0, 0);
>
> input_set_abs_params(gamepad, ABS_HAT0X, -1, 1, 0, 0);
> --
> 2.51.2.1041.gc1ab5b90ca-goo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] HID: playstation: Center initial joystick axes to prevent spurious events
2026-02-24 21:10 ` Guenter Roeck
@ 2026-02-24 22:44 ` Siarhei Vishniakou
2026-02-24 23:34 ` Guenter Roeck
0 siblings, 1 reply; 7+ messages in thread
From: Siarhei Vishniakou @ 2026-02-24 22:44 UTC (permalink / raw)
To: Guenter Roeck
Cc: Jiri Kosina, Benjamin Tissoires, Roderick Colenbrander,
linux-input, linux-kernel
вт, 24 февр. 2026 г. в 13:10, Guenter Roeck <linux@roeck-us.net>:
>
> On Tue, Nov 11, 2025 at 03:45:19PM -0800, Siarhei Vishniakou wrote:
> > When a new PlayStation gamepad (DualShock 4 or DualSense) is initialized,
> > the input subsystem sets the default value for its absolute axes (e.g.,
> > ABS_X, ABS_Y) to 0.
> >
> > However, the hardware's actual neutral/resting state for these joysticks
> > is 128 (0x80). This creates a mismatch.
> >
> > When the first HID report arrives from the device, the driver sees the
> > resting value of 128. The kernel compares this to its initial state of 0
> > and incorrectly interprets this as a delta (0 -> 128). Consequently, it
> > generates EV_ABS events for this initial, non-existent movement.
> >
> > This behavior can fail userspace 'sanity check' tests (e.g., in
> > Android CTS) that correctly assert no motion events should be generated
> > from a device that is already at rest.
> >
> > This patch fixes the issue by explicitly setting the initial value of the
> > main joystick axes (e.g., ABS_X, ABS_Y, ABS_RX, ABS_RY) to 128 (0x80)
> > in the common ps_gamepad_create() function.
> >
> > This aligns the kernel's initial state with the hardware's expected
> > neutral state, ensuring that the first report (at 128) produces no
> > delta and thus, no spurious event.
> >
> > Signed-off-by: Siarhei Vishniakou <svv@google.com>
> > Reviewed-by: Benjamin Tissoires <bentiss@kernel.org>
> > ---
> > drivers/hid/hid-playstation.c | 5 +++++
> > 1 file changed, 5 insertions(+)
> >
> > diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
> > index 1468fb11e39d..a145b5ea4405 100644
> > --- a/drivers/hid/hid-playstation.c
> > +++ b/drivers/hid/hid-playstation.c
> > @@ -718,11 +718,16 @@ static struct input_dev *ps_gamepad_create(struct hid_device *hdev,
> > if (IS_ERR(gamepad))
> > return ERR_CAST(gamepad);
> >
> > + /* Set initial resting state for joysticks to 128 (center) */
> > input_set_abs_params(gamepad, ABS_X, 0, 255, 0, 0);
> > + gamepad->absinfo[ABS_X].value = 128;
>
> input_set_abs_params() can fail to allocate absinfo. If that happens,
> this will crash. AI suggests setting the value with input_abs_set_val()
> to ensure that the value is checked before dereferencing.
>
> Guenter
>
> > input_set_abs_params(gamepad, ABS_Y, 0, 255, 0, 0);
> > + gamepad->absinfo[ABS_Y].value = 128;
> > input_set_abs_params(gamepad, ABS_Z, 0, 255, 0, 0);
> > input_set_abs_params(gamepad, ABS_RX, 0, 255, 0, 0);
> > + gamepad->absinfo[ABS_RX].value = 128;
> > input_set_abs_params(gamepad, ABS_RY, 0, 255, 0, 0);
> > + gamepad->absinfo[ABS_RY].value = 128;
> > input_set_abs_params(gamepad, ABS_RZ, 0, 255, 0, 0);
> >
> > input_set_abs_params(gamepad, ABS_HAT0X, -1, 1, 0, 0);
> > --
> > 2.51.2.1041.gc1ab5b90ca-goo
The function `input_set_abs_params` is ill-formed. If this call can
fail, then it should return some kind of error result instead of void.
In addition, the function name doesn't suggest that it's going to be
doing any allocations.
So the (short-term) fix should be something like this:
/* Set initial resting state for joysticks to 128 (center) */
input_set_abs_params(gamepad, ABS_X, 0, 255, 0, 0);
+ if (gamepad->absinfo == NULL) {
+ // input_set_abs_params allocates "absinfo" struct, which could fail.
+ return ERR_CAST(gamepad);
+ }
A better long-term option would be to change the signature of
input_set_abs_params to return a bool, or to add an explicit
allocation step (looking at code search, there aren't too many places
using this API today, but this might break 3-rd party stuff).
Curious to hear maintainers' opinions on this.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] HID: playstation: Center initial joystick axes to prevent spurious events
2026-02-24 22:44 ` Siarhei Vishniakou
@ 2026-02-24 23:34 ` Guenter Roeck
0 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2026-02-24 23:34 UTC (permalink / raw)
To: Siarhei Vishniakou
Cc: Jiri Kosina, Benjamin Tissoires, Roderick Colenbrander,
linux-input, linux-kernel
On 2/24/26 14:44, Siarhei Vishniakou wrote:
> вт, 24 февр. 2026 г. в 13:10, Guenter Roeck <linux@roeck-us.net>:
>>
>> On Tue, Nov 11, 2025 at 03:45:19PM -0800, Siarhei Vishniakou wrote:
>>> When a new PlayStation gamepad (DualShock 4 or DualSense) is initialized,
>>> the input subsystem sets the default value for its absolute axes (e.g.,
>>> ABS_X, ABS_Y) to 0.
>>>
>>> However, the hardware's actual neutral/resting state for these joysticks
>>> is 128 (0x80). This creates a mismatch.
>>>
>>> When the first HID report arrives from the device, the driver sees the
>>> resting value of 128. The kernel compares this to its initial state of 0
>>> and incorrectly interprets this as a delta (0 -> 128). Consequently, it
>>> generates EV_ABS events for this initial, non-existent movement.
>>>
>>> This behavior can fail userspace 'sanity check' tests (e.g., in
>>> Android CTS) that correctly assert no motion events should be generated
>>> from a device that is already at rest.
>>>
>>> This patch fixes the issue by explicitly setting the initial value of the
>>> main joystick axes (e.g., ABS_X, ABS_Y, ABS_RX, ABS_RY) to 128 (0x80)
>>> in the common ps_gamepad_create() function.
>>>
>>> This aligns the kernel's initial state with the hardware's expected
>>> neutral state, ensuring that the first report (at 128) produces no
>>> delta and thus, no spurious event.
>>>
>>> Signed-off-by: Siarhei Vishniakou <svv@google.com>
>>> Reviewed-by: Benjamin Tissoires <bentiss@kernel.org>
>>> ---
>>> drivers/hid/hid-playstation.c | 5 +++++
>>> 1 file changed, 5 insertions(+)
>>>
>>> diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
>>> index 1468fb11e39d..a145b5ea4405 100644
>>> --- a/drivers/hid/hid-playstation.c
>>> +++ b/drivers/hid/hid-playstation.c
>>> @@ -718,11 +718,16 @@ static struct input_dev *ps_gamepad_create(struct hid_device *hdev,
>>> if (IS_ERR(gamepad))
>>> return ERR_CAST(gamepad);
>>>
>>> + /* Set initial resting state for joysticks to 128 (center) */
>>> input_set_abs_params(gamepad, ABS_X, 0, 255, 0, 0);
>>> + gamepad->absinfo[ABS_X].value = 128;
>>
>> input_set_abs_params() can fail to allocate absinfo. If that happens,
>> this will crash. AI suggests setting the value with input_abs_set_val()
>> to ensure that the value is checked before dereferencing.
>>
>> Guenter
>>
>>> input_set_abs_params(gamepad, ABS_Y, 0, 255, 0, 0);
>>> + gamepad->absinfo[ABS_Y].value = 128;
>>> input_set_abs_params(gamepad, ABS_Z, 0, 255, 0, 0);
>>> input_set_abs_params(gamepad, ABS_RX, 0, 255, 0, 0);
>>> + gamepad->absinfo[ABS_RX].value = 128;
>>> input_set_abs_params(gamepad, ABS_RY, 0, 255, 0, 0);
>>> + gamepad->absinfo[ABS_RY].value = 128;
>>> input_set_abs_params(gamepad, ABS_RZ, 0, 255, 0, 0);
>>>
>>> input_set_abs_params(gamepad, ABS_HAT0X, -1, 1, 0, 0);
>>> --
>>> 2.51.2.1041.gc1ab5b90ca-goo
>
> The function `input_set_abs_params` is ill-formed. If this call can
> fail, then it should return some kind of error result instead of void.
> In addition, the function name doesn't suggest that it's going to be
> doing any allocations.
> So the (short-term) fix should be something like this:
>
> /* Set initial resting state for joysticks to 128 (center) */
> input_set_abs_params(gamepad, ABS_X, 0, 255, 0, 0);
> + if (gamepad->absinfo == NULL) {
> + // input_set_abs_params allocates "absinfo" struct, which could fail.
> + return ERR_CAST(gamepad);
> + }
>
That function is called about 870+ times.
> A better long-term option would be to change the signature of
> input_set_abs_params to return a bool, or to add an explicit
> allocation step (looking at code search, there aren't too many places
> using this API today, but this might break 3-rd party stuff).
>
> Curious to hear maintainers' opinions on this.
The same would apply to the following macro.
static inline void input_abs_set_##_suffix(struct input_dev *dev, \
unsigned int axis, int val) \
{ \
input_alloc_absinfo(dev); \
if (dev->absinfo) \
dev->absinfo[axis]._item = val; \
}
which is called some 170 times with no error check.
Overall, input_abs_set_val() and input_alloc_absinfo() are widely used
in the kernel. Changing that would be monumental. While I agree that the
current code is less than perfect, I think the immediate fix should be
to avoid the crash and use the same mechanism that is used by all other
drivers.
Of course, I am not the maintainer, so that is just my personal opinion.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-02-24 23:35 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-11 23:45 [PATCH v2] HID: playstation: Center initial joystick axes to prevent spurious events Siarhei Vishniakou
2025-12-01 18:30 ` Siarhei Vishniakou
2025-12-02 8:25 ` Benjamin Tissoires
2025-12-19 13:05 ` Benjamin Tissoires
2026-02-24 21:10 ` Guenter Roeck
2026-02-24 22:44 ` Siarhei Vishniakou
2026-02-24 23:34 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®