Skip to content

Commit ae9b956

Browse files
dtorBenjamin Tissoires
authored andcommitted
HID: simplify snto32()
snto32() does exactly what sign_extend32() does, but handles potentially malformed data coming from the device. Keep the checks, but then call sign_extend32() to perform the actual conversion. Signed-off-by: Dmitry Torokhov <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Benjamin Tissoires <[email protected]>
1 parent 6159501 commit ae9b956

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

drivers/hid/hid-core.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,9 +1313,7 @@ int hid_open_report(struct hid_device *device)
13131313
EXPORT_SYMBOL_GPL(hid_open_report);
13141314

13151315
/*
1316-
* Convert a signed n-bit integer to signed 32-bit integer. Common
1317-
* cases are done through the compiler, the screwed things has to be
1318-
* done by hand.
1316+
* Convert a signed n-bit integer to signed 32-bit integer.
13191317
*/
13201318

13211319
static s32 snto32(__u32 value, unsigned n)
@@ -1326,12 +1324,7 @@ static s32 snto32(__u32 value, unsigned n)
13261324
if (n > 32)
13271325
n = 32;
13281326

1329-
switch (n) {
1330-
case 8: return ((__s8)value);
1331-
case 16: return ((__s16)value);
1332-
case 32: return ((__s32)value);
1333-
}
1334-
return value & (1 << (n - 1)) ? value | (~0U << n) : value;
1327+
return sign_extend32(value, n - 1);
13351328
}
13361329

13371330
s32 hid_snto32(__u32 value, unsigned n)

0 commit comments

Comments
 (0)