diff options
author | Jiri Kosina <jkosina@suse.cz> | 2016-05-17 12:41:22 +0200 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2016-05-17 12:41:22 +0200 |
commit | 3390e579b3dac71e630ed879a73c5ac3b4447045 (patch) | |
tree | fcd7f4118654286c1e634c87e4ad3efcea3c637d /drivers/hid/hid-core.c | |
parent | 27fd38c5226ed0f1712d071880fa8e739eb78650 (diff) | |
parent | 282bf1fe6dca4b768d6bedc14aea1b82c36241c1 (diff) | |
download | linux-3390e579b3dac71e630ed879a73c5ac3b4447045.tar.bz2 |
Merge branch 'for-4.7/upstream' into for-linus
Conflicts:
drivers/hid/usbhid/hid-quirks.c
Diffstat (limited to 'drivers/hid/hid-core.c')
-rw-r--r-- | drivers/hid/hid-core.c | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 875ff6e0b4d0..8ea3a26360e9 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -1129,49 +1129,46 @@ EXPORT_SYMBOL_GPL(hid_field_extract); static void __implement(u8 *report, unsigned offset, int n, u32 value) { unsigned int idx = offset / 8; - unsigned int size = offset + n; unsigned int bit_shift = offset % 8; int bits_to_set = 8 - bit_shift; - u8 bit_mask = 0xff << bit_shift; while (n - bits_to_set >= 0) { - report[idx] &= ~bit_mask; + report[idx] &= ~(0xff << bit_shift); report[idx] |= value << bit_shift; value >>= bits_to_set; n -= bits_to_set; bits_to_set = 8; - bit_mask = 0xff; bit_shift = 0; idx++; } /* last nibble */ if (n) { - if (size % 8) - bit_mask &= (1U << (size % 8)) - 1; - report[idx] &= ~bit_mask; - report[idx] |= (value << bit_shift) & bit_mask; + u8 bit_mask = ((1U << n) - 1); + report[idx] &= ~(bit_mask << bit_shift); + report[idx] |= value << bit_shift; } } static void implement(const struct hid_device *hid, u8 *report, unsigned offset, unsigned n, u32 value) { - u64 m; - - if (n > 32) { + if (unlikely(n > 32)) { hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n", __func__, n, current->comm); n = 32; + } else if (n < 32) { + u32 m = (1U << n) - 1; + + if (unlikely(value > m)) { + hid_warn(hid, + "%s() called with too large value %d (n: %d)! (%s)\n", + __func__, value, n, current->comm); + WARN_ON(1); + value &= m; + } } - m = (1ULL << n) - 1; - if (value > m) - hid_warn(hid, "%s() called with too large value %d! (%s)\n", - __func__, value, current->comm); - WARN_ON(value > m); - value &= m; - __implement(report, offset, n, value); } |