HID: core: don't use negative operands when shift
authorAndy Shevchenko <andy.shevchenko@gmail.com>
Tue, 13 Jun 2017 09:22:22 +0000 (12:22 +0300)
committerJiri Kosina <jkosina@suse.cz>
Tue, 13 Jun 2017 12:29:20 +0000 (14:29 +0200)
The recent C standard in 6.5.7 paragraph 4 defines that operands for
bitwise shift operators should be non-negative, otherwise it's an
undefined behaviour.

Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Acked-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hid-core.c

index 37084b6457851ebe0d52361e327db9df07b86b2c..8017de4e5c1155146fb66ef22f6df5497415eafd 100644 (file)
@@ -1046,7 +1046,7 @@ static s32 snto32(__u32 value, unsigned n)
        case 16: return ((__s16)value);
        case 32: return ((__s32)value);
        }
-       return value & (1 << (n - 1)) ? value | (-1 << n) : value;
+       return value & (1 << (n - 1)) ? value | (~0U << n) : value;
 }
 
 s32 hid_snto32(__u32 value, unsigned n)