linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] HID: logitech: fix a used uninitialized GCC warning
@ 2018-09-13  3:52 zhong jiang
  2018-09-13  7:01 ` Benjamin Tissoires
  0 siblings, 1 reply; 3+ messages in thread
From: zhong jiang @ 2018-09-13  3:52 UTC (permalink / raw)
  To: jikos, benjamin.tissoires; +Cc: linux-input, linux-kernel

Fix the following compile warning:

drivers/hid/hid-logitech-hidpp.c: In function ‘hi_res_scroll_enable’:
drivers/hid/hid-logitech-hidpp.c:2714:54: warning: ‘multiplier’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  hidpp->vertical_wheel_counter.resolution_multiplier = multiplier;

Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
 drivers/hid/hid-logitech-hidpp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index 5f0c080..83c43dd 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -2696,7 +2696,7 @@ static int hi_res_scroll_look_up_microns(__u32 product_id)
 static int hi_res_scroll_enable(struct hidpp_device *hidpp)
 {
 	int ret;
-	u8 multiplier;
+	u8 uninitialized_var(multiplier);
 
 	if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL_X2121) {
 		ret = hidpp_hrw_set_wheel_mode(hidpp, false, true, false);
-- 
1.7.12.4


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

* Re: [PATCH] HID: logitech: fix a used uninitialized GCC warning
  2018-09-13  3:52 [PATCH] HID: logitech: fix a used uninitialized GCC warning zhong jiang
@ 2018-09-13  7:01 ` Benjamin Tissoires
  2018-09-13  7:39   ` zhong jiang
  0 siblings, 1 reply; 3+ messages in thread
From: Benjamin Tissoires @ 2018-09-13  7:01 UTC (permalink / raw)
  To: zhongjiang; +Cc: Jiri Kosina, open list:HID CORE LAYER, lkml

On Thu, Sep 13, 2018 at 6:04 AM zhong jiang <zhongjiang@huawei.com> wrote:
>
> Fix the following compile warning:
>
> drivers/hid/hid-logitech-hidpp.c: In function ‘hi_res_scroll_enable’:
> drivers/hid/hid-logitech-hidpp.c:2714:54: warning: ‘multiplier’ may be used uninitialized in this function [-Wmaybe-uninitialized]
>   hidpp->vertical_wheel_counter.resolution_multiplier = multiplier;
>
> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
> ---
>  drivers/hid/hid-logitech-hidpp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
> index 5f0c080..83c43dd 100644
> --- a/drivers/hid/hid-logitech-hidpp.c
> +++ b/drivers/hid/hid-logitech-hidpp.c
> @@ -2696,7 +2696,7 @@ static int hi_res_scroll_look_up_microns(__u32 product_id)
>  static int hi_res_scroll_enable(struct hidpp_device *hidpp)
>  {
>         int ret;
> -       u8 multiplier;
> +       u8 uninitialized_var(multiplier);

I think your patch is correct (multiplier will be set given the code
path), but IMO, it feels terribly wrong to explicitly remove this
warning this way. The problem is that if someone else adds a new piece
of code, we might miss the fact that multiplier is not set and we
might show garbage in the hid_info call.

Why don't you initialize the value to 8 as in the 'else' statement and
remove the now duplicated assignement in this else statement?

Cheers,
Benjamin

>
>         if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL_X2121) {
>                 ret = hidpp_hrw_set_wheel_mode(hidpp, false, true, false);
> --
> 1.7.12.4
>

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

* Re: [PATCH] HID: logitech: fix a used uninitialized GCC warning
  2018-09-13  7:01 ` Benjamin Tissoires
@ 2018-09-13  7:39   ` zhong jiang
  0 siblings, 0 replies; 3+ messages in thread
From: zhong jiang @ 2018-09-13  7:39 UTC (permalink / raw)
  To: Benjamin Tissoires; +Cc: Jiri Kosina, HID CORE LAYER, lkml, 

On 2018/9/13 15:01, Benjamin Tissoires wrote:
> On Thu, Sep 13, 2018 at 6:04 AM zhong jiang <zhongjiang@huawei.com> wrote:
>> Fix the following compile warning:
>>
>> drivers/hid/hid-logitech-hidpp.c: In function ‘hi_res_scroll_enable’:
>> drivers/hid/hid-logitech-hidpp.c:2714:54: warning: ‘multiplier’ may be used uninitialized in this function [-Wmaybe-uninitialized]
>>   hidpp->vertical_wheel_counter.resolution_multiplier = multiplier;
>>
>> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
>> ---
>>  drivers/hid/hid-logitech-hidpp.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
>> index 5f0c080..83c43dd 100644
>> --- a/drivers/hid/hid-logitech-hidpp.c
>> +++ b/drivers/hid/hid-logitech-hidpp.c
>> @@ -2696,7 +2696,7 @@ static int hi_res_scroll_look_up_microns(__u32 product_id)
>>  static int hi_res_scroll_enable(struct hidpp_device *hidpp)
>>  {
>>         int ret;
>> -       u8 multiplier;
>> +       u8 uninitialized_var(multiplier);
> I think your patch is correct (multiplier will be set given the code
> path), but IMO, it feels terribly wrong to explicitly remove this
> warning this way. The problem is that if someone else adds a new piece
> of code, we might miss the fact that multiplier is not set and we
> might show garbage in the hid_info call.
Make sense.
>
> Why don't you initialize the value to 8 as in the 'else' statement and
> remove the now duplicated assignement in this else statement?
Will do in v2.  Thank you for your suggestion.

Thanks,
zhong jiang
> Cheers,
> Benjamin
>
>>         if (hidpp->quirks & HIDPP_QUIRK_HI_RES_SCROLL_X2121) {
>>                 ret = hidpp_hrw_set_wheel_mode(hidpp, false, true, false);
>> --
>> 1.7.12.4
>>
> .
>



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

end of thread, other threads:[~2018-09-13  7:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-13  3:52 [PATCH] HID: logitech: fix a used uninitialized GCC warning zhong jiang
2018-09-13  7:01 ` Benjamin Tissoires
2018-09-13  7:39   ` zhong jiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).