Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sony-laptop: Fix handling sony_nc_hotkeys_decode result

sony_nv_hotkeys_decode can return a negative value. real_ev is a u32 variable.
The check for real_ev > 0 is incorrect.

Use an intermediate ret variable.

The problem has been detected using proposed semantic patch
scripts/coccinelle/tests/assign_signed_to_unsigned.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2046107

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
[dvhart: clarify commit msg, drop superfluous else block]
Signed-off-by: Darren Hart <dvhart@linux.intel.com>

authored by

Andrzej Hajda and committed by
Darren Hart
963406ff daea5a65

+7 -6
+7 -6
drivers/platform/x86/sony-laptop.c
··· 1204 1204 { 1205 1205 u32 real_ev = event; 1206 1206 u8 ev_type = 0; 1207 + int ret; 1208 + 1207 1209 dprintk("sony_nc_notify, event: 0x%.2x\n", event); 1208 1210 1209 1211 if (event >= 0x90) { ··· 1227 1225 case 0x0100: 1228 1226 case 0x0127: 1229 1227 ev_type = HOTKEY; 1230 - real_ev = sony_nc_hotkeys_decode(event, handle); 1228 + ret = sony_nc_hotkeys_decode(event, handle); 1231 1229 1232 - if (real_ev > 0) 1233 - sony_laptop_report_input_event(real_ev); 1234 - else 1235 - /* restore the original event for reporting */ 1236 - real_ev = event; 1230 + if (ret > 0) { 1231 + sony_laptop_report_input_event(ret); 1232 + real_ev = ret; 1233 + } 1237 1234 1238 1235 break; 1239 1236