HID: logitech-hidpp: initialize level variable
Subsystems (3)
PATCH 1/1 HID: logitech-hidpp: initialize level variable
From: Tom Rix <[email protected]>
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.
--- drivers/hid/hid-logitech-hidpp.c | 1 + 1 file changed, 1 insertion(+)
drivers/hid/hid-logitech-hidpp.c +1 -0
@@ -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 ) {
Signature · 1 line
2.26.3
Quoted 27 lines · On Fri, 2021-05-07 at 12:18 -0700, [email protected] wrote:
From: Tom Rix <[email protected]>
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 newerdevices")
Signed-off-by Tom Rix <[email protected]>---
drivers/hid/hid-logitech-hidpp.c | 1 +1 file changed, 1 insertion(+)drivers/hid/hid-logitech- renamed from drivers/hid/hid-logitech-hidpp.c +0
-0
hidpp.c
index69670ca7e1e1..61635e629469100644drivers/hid/hid-logitech-hidpp.c +0
-0@@ -1265,6 +1265,7 @@ static int hidpp20_battery_map_status_voltage(u8 data[3 ], int *voltage, int status;
Quoted 6 lines
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 :)
Cheers,
Filipe Laíns
Quoted 34 lines · Filipe Laíns
Quoted 25 lines
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 newerdevices")
Signed-off-by Tom Rix <[email protected]>---
drivers/hid/hid-logitech-hidpp.c | 1 +1 file changed, 1 insertion(+)drivers/hid/hid-logitech- renamed from drivers/hid/hid-logitech-hidpp.c +0
-0
hidpp.c
index69670ca7e1e1..61635e629469100644drivers/hid/hid-logitech-hidpp.c +0
-0@@ -1265,6 +1265,7 @@ static int hidpp20_battery_map_status_voltage(u8 data[3 ], int *voltage, int status;Quoted 6 lines
long flags = (long) data[2];
+ *level =POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
if (flags &0x80)
switch (flags &0x07) {Hi Tom,
Quoted 4 lines
Taking a look at how this function is used, it does make sense to initialize the level, thank you :)
Reviewed-by Filipe Laíns <[email protected]>
Applied, thanks.
Signature · 2 lines
Jiri Kosina SUSE Labs