* [PATCH] HID: logitech-hidpp: initialize level variable
@ 2021-05-07 19:18 trix
2021-05-16 3:21 ` Filipe Laíns
0 siblings, 1 reply; 3+ messages in thread
From: trix @ 2021-05-07 19:18 UTC (permalink / raw)
To: jikos, benjamin.tissoires, pedro; +Cc: linux-input, linux-kernel, Tom Rix
From: Tom Rix <trix@redhat.com>
Static analysis reports this representative problem
hid-logitech-hidpp.c:1356:23: warning: Assigned value is
garbage or undefined
hidpp->battery.level = level;
^ ~~~~~
In some cases, 'level' is never set in hidpp20_battery_map_status_voltage()
Since level is not available on all hw, initialize level to unknown.
Fixes: be281368f297 ("hid-logitech-hidpp: read battery voltage from newer devices")
Signed-off-by: Tom Rix <trix@redhat.com>
---
drivers/hid/hid-logitech-hidpp.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index 69670ca7e1e1..61635e629469 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -1265,6 +1265,7 @@ static int hidpp20_battery_map_status_voltage(u8 data[3], int *voltage,
int status;
long flags = (long) data[2];
+ *level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
if (flags & 0x80)
switch (flags & 0x07) {
--
2.26.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] HID: logitech-hidpp: initialize level variable
2021-05-07 19:18 [PATCH] HID: logitech-hidpp: initialize level variable trix
@ 2021-05-16 3:21 ` Filipe Laíns
2021-05-26 10:39 ` Jiri Kosina
0 siblings, 1 reply; 3+ messages in thread
From: Filipe Laíns @ 2021-05-16 3:21 UTC (permalink / raw)
To: trix, jikos, benjamin.tissoires, pedro; +Cc: linux-input, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1501 bytes --]
On Fri, 2021-05-07 at 12:18 -0700, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
>
> Static analysis reports this representative problem
>
> hid-logitech-hidpp.c:1356:23: warning: Assigned value is
> garbage or undefined
> hidpp->battery.level = level;
> ^ ~~~~~
>
> In some cases, 'level' is never set in hidpp20_battery_map_status_voltage()
> Since level is not available on all hw, initialize level to unknown.
>
> Fixes: be281368f297 ("hid-logitech-hidpp: read battery voltage from newer
> devices")
> Signed-off-by: Tom Rix <trix@redhat.com>
> ---
> drivers/hid/hid-logitech-hidpp.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-
> hidpp.c
> index 69670ca7e1e1..61635e629469 100644
> --- a/drivers/hid/hid-logitech-hidpp.c
> +++ b/drivers/hid/hid-logitech-hidpp.c
> @@ -1265,6 +1265,7 @@ static int hidpp20_battery_map_status_voltage(u8
> data[3], int *voltage,
> int status;
>
> long flags = (long) data[2];
> + *level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
>
> if (flags & 0x80)
> switch (flags & 0x07) {
Hi Tom,
Taking a look at how this function is used, it does make sense to initialize the
level, thank you :)
Reviewed-by: Filipe Laíns <lains@riseup.net>
Cheers,
Filipe Laíns
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] HID: logitech-hidpp: initialize level variable
2021-05-16 3:21 ` Filipe Laíns
@ 2021-05-26 10:39 ` Jiri Kosina
0 siblings, 0 replies; 3+ messages in thread
From: Jiri Kosina @ 2021-05-26 10:39 UTC (permalink / raw)
To: Filipe Laíns
Cc: trix, benjamin.tissoires, pedro, linux-input, linux-kernel
On Sun, 16 May 2021, Filipe Laíns wrote:
> > Static analysis reports this representative problem
> >
> > hid-logitech-hidpp.c:1356:23: warning: Assigned value is
> > garbage or undefined
> > hidpp->battery.level = level;
> > ^ ~~~~~
> >
> > In some cases, 'level' is never set in hidpp20_battery_map_status_voltage()
> > Since level is not available on all hw, initialize level to unknown.
> >
> > Fixes: be281368f297 ("hid-logitech-hidpp: read battery voltage from newer
> > devices")
> > Signed-off-by: Tom Rix <trix@redhat.com>
> > ---
> > drivers/hid/hid-logitech-hidpp.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-
> > hidpp.c
> > index 69670ca7e1e1..61635e629469 100644
> > --- a/drivers/hid/hid-logitech-hidpp.c
> > +++ b/drivers/hid/hid-logitech-hidpp.c
> > @@ -1265,6 +1265,7 @@ static int hidpp20_battery_map_status_voltage(u8
> > data[3], int *voltage,
> > int status;
> >
> > long flags = (long) data[2];
> > + *level = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
> >
> > if (flags & 0x80)
> > switch (flags & 0x07) {
>
> Hi Tom,
>
> Taking a look at how this function is used, it does make sense to initialize the
> level, thank you :)
>
> Reviewed-by: Filipe Laíns <lains@riseup.net>
Applied, thanks.
--
Jiri Kosina
SUSE Labs
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-05-26 10:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-07 19:18 [PATCH] HID: logitech-hidpp: initialize level variable trix
2021-05-16 3:21 ` Filipe Laíns
2021-05-26 10:39 ` Jiri Kosina
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.