[PATCH] HID: haptic: don't write an uninitialized value to unhandled usages

Karl Mehltretter posted 1 patch 1 month, 3 weeks ago
drivers/hid/hid-haptic.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] HID: haptic: don't write an uninitialized value to unhandled usages
Posted by Karl Mehltretter 1 month, 3 weeks ago
fill_effect_buf() initializes value only for the four haptic usages
handled by its switch, but writes it to field->value[] for every usage.
An unhandled usage can therefore receive either an uninitialized value
or one left over from the previous usage. hid_output_report() then
serializes that value into the effect's report buffer.

Skip unhandled usages instead. This also matches switch_mode(), which
only updates fields it recognizes.

Found with Clang's -Wconditional-uninitialized.

Fixes: 344ff3584957 ("HID: haptic: initialize haptic device")
Assisted-by: Claude:claude-fable-5
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
 drivers/hid/hid-haptic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hid/hid-haptic.c b/drivers/hid/hid-haptic.c
index deadab28cdbef..66d90f0f78a3b 100644
--- a/drivers/hid/hid-haptic.c
+++ b/drivers/hid/hid-haptic.c
@@ -187,7 +187,7 @@ static void fill_effect_buf(struct hid_haptic_device *haptic,
 				value = waveform_ordinal;
 				break;
 			default:
-				break;
+				continue;
 			}
 
 			field->value[j] = value;
-- 
2.53.0
Re: [PATCH] HID: haptic: don't write an uninitialized value to unhandled usages
Posted by Jiri Kosina 1 month, 2 weeks ago
On Sat, 8 Aug 2026, Karl Mehltretter wrote:

> fill_effect_buf() initializes value only for the four haptic usages
> handled by its switch, but writes it to field->value[] for every usage.
> An unhandled usage can therefore receive either an uninitialized value
> or one left over from the previous usage. hid_output_report() then
> serializes that value into the effect's report buffer.
> 
> Skip unhandled usages instead. This also matches switch_mode(), which
> only updates fields it recognizes.
> 
> Found with Clang's -Wconditional-uninitialized.
> 
> Fixes: 344ff3584957 ("HID: haptic: initialize haptic device")
> Assisted-by: Claude:claude-fable-5
> Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
> ---
>  drivers/hid/hid-haptic.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hid/hid-haptic.c b/drivers/hid/hid-haptic.c
> index deadab28cdbef..66d90f0f78a3b 100644
> --- a/drivers/hid/hid-haptic.c
> +++ b/drivers/hid/hid-haptic.c
> @@ -187,7 +187,7 @@ static void fill_effect_buf(struct hid_haptic_device *haptic,
>  				value = waveform_ordinal;
>  				break;
>  			default:
> -				break;
> +				continue;
>  			}
>  

Applied, thanks.

-- 
Jiri Kosina
SUSE Labs