[PATCH] HID: pidff: Fix condition effect bit clearing

Tomasz Pakuła posted 1 patch 4 days, 8 hours ago
There is a newer version of this series
drivers/hid/usbhid/hid-pidff.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
[PATCH] HID: pidff: Fix condition effect bit clearing
Posted by Tomasz Pakuła 4 days, 8 hours ago
As reported by MPDarkGuy on discord, NULL pointer dereferences were
happening because not all the conditional effects bits were cleared.

Properly clear all conditional effect bits from ffbit

Signed-off-by: Tomasz Pakuła <tomasz.pakula.oficjalny@gmail.com>
---

Urgent for 6.19 rc period and backports for 6.18

 drivers/hid/usbhid/hid-pidff.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c
index a4e700b40ba9..56d6af39ba81 100644
--- a/drivers/hid/usbhid/hid-pidff.c
+++ b/drivers/hid/usbhid/hid-pidff.c
@@ -1452,10 +1452,13 @@ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev)
 		hid_warn(pidff->hid, "unknown ramp effect layout\n");
 
 	if (PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1)) {
-		if (test_and_clear_bit(FF_SPRING, dev->ffbit)   ||
-		    test_and_clear_bit(FF_DAMPER, dev->ffbit)   ||
-		    test_and_clear_bit(FF_FRICTION, dev->ffbit) ||
-		    test_and_clear_bit(FF_INERTIA, dev->ffbit))
+		bool test = false;
+
+		test |= test_and_clear_bit(FF_SPRING, dev->ffbit);
+		test |= test_and_clear_bit(FF_DAMPER, dev->ffbit);
+		test |= test_and_clear_bit(FF_FRICTION, dev->ffbit);
+		test |= test_and_clear_bit(FF_INERTIA, dev->ffbit);
+		if (test)
 			hid_warn(pidff->hid, "unknown condition effect layout\n");
 	}
 
-- 
2.52.0

Re: [PATCH] HID: pidff: Fix condition effect bit clearing
Posted by Jiri Slaby 3 days, 14 hours ago
On 03. 02. 26, 18:42, Tomasz Pakuła wrote:
> As reported by MPDarkGuy on discord, NULL pointer dereferences were
> happening because not all the conditional effects bits were cleared.
> 
> Properly clear all conditional effect bits from ffbit
> 
> Signed-off-by: Tomasz Pakuła <tomasz.pakula.oficjalny@gmail.com>
> ---
> 
> Urgent for 6.19 rc period and backports for 6.18
> 
>   drivers/hid/usbhid/hid-pidff.c | 11 +++++++----
>   1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c
> index a4e700b40ba9..56d6af39ba81 100644
> --- a/drivers/hid/usbhid/hid-pidff.c
> +++ b/drivers/hid/usbhid/hid-pidff.c
> @@ -1452,10 +1452,13 @@ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev)
>   		hid_warn(pidff->hid, "unknown ramp effect layout\n");
>   
>   	if (PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1)) {
> -		if (test_and_clear_bit(FF_SPRING, dev->ffbit)   ||
> -		    test_and_clear_bit(FF_DAMPER, dev->ffbit)   ||
> -		    test_and_clear_bit(FF_FRICTION, dev->ffbit) ||
> -		    test_and_clear_bit(FF_INERTIA, dev->ffbit))
> +		bool test = false;
> +
> +		test |= test_and_clear_bit(FF_SPRING, dev->ffbit);
> +		test |= test_and_clear_bit(FF_DAMPER, dev->ffbit);
> +		test |= test_and_clear_bit(FF_FRICTION, dev->ffbit);
> +		test |= test_and_clear_bit(FF_INERTIA, dev->ffbit);

You could use | directly in the if, perhaps with a comment.

> +		if (test)
>   			hid_warn(pidff->hid, "unknown condition effect layout\n");
>   	}
>   

-- 
js
suse labs

Re: [PATCH] HID: pidff: Fix condition effect bit clearing
Posted by Tomasz Pakuła 3 days, 13 hours ago
On Wed, 2026-02-04 at 12:58 +0100, Jiri Slaby wrote:
> You could use | directly in the if, perhaps with a comment.
> 

That's actually pretty neat. Didn't think about it. Thanks!

Tomasz
Re: [PATCH] HID: pidff: Fix condition effect bit clearing
Posted by Greg KH 3 days, 21 hours ago
On Tue, Feb 03, 2026 at 06:42:41PM +0100, Tomasz Pakuła wrote:
> As reported by MPDarkGuy on discord, NULL pointer dereferences were
> happening because not all the conditional effects bits were cleared.
> 
> Properly clear all conditional effect bits from ffbit
> 
> Signed-off-by: Tomasz Pakuła <tomasz.pakula.oficjalny@gmail.com>
> ---
> 
> Urgent for 6.19 rc period and backports for 6.18
> 
>  drivers/hid/usbhid/hid-pidff.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c
> index a4e700b40ba9..56d6af39ba81 100644
> --- a/drivers/hid/usbhid/hid-pidff.c
> +++ b/drivers/hid/usbhid/hid-pidff.c
> @@ -1452,10 +1452,13 @@ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev)
>  		hid_warn(pidff->hid, "unknown ramp effect layout\n");
>  
>  	if (PIDFF_FIND_FIELDS(set_condition, PID_SET_CONDITION, 1)) {
> -		if (test_and_clear_bit(FF_SPRING, dev->ffbit)   ||
> -		    test_and_clear_bit(FF_DAMPER, dev->ffbit)   ||
> -		    test_and_clear_bit(FF_FRICTION, dev->ffbit) ||
> -		    test_and_clear_bit(FF_INERTIA, dev->ffbit))
> +		bool test = false;
> +
> +		test |= test_and_clear_bit(FF_SPRING, dev->ffbit);
> +		test |= test_and_clear_bit(FF_DAMPER, dev->ffbit);
> +		test |= test_and_clear_bit(FF_FRICTION, dev->ffbit);
> +		test |= test_and_clear_bit(FF_INERTIA, dev->ffbit);
> +		if (test)
>  			hid_warn(pidff->hid, "unknown condition effect layout\n");
>  	}
>  
> -- 
> 2.52.0
> 
> 

<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read:
    https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>