From: Tom Rix Date: Fri, 7 May 2021 19:18:19 +0000 (-0700) Subject: HID: logitech-hidpp: initialize level variable X-Git-Tag: v5.10.43~123 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=39b92726a38092c704c4e1bcc8262a8959ae978e;p=thirdparty%2Fkernel%2Fstable.git HID: logitech-hidpp: initialize level variable [ Upstream commit 81c8bf9170477d453b24a6bc3300d201d641e645 ] 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 Reviewed-by: Filipe LaĆ­ns Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 74ebfb12c360e..66b1051620390 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -1259,6 +1259,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) {