From 85d08340c3de1126467db4e69140fe483d91c114 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Sat, 2 Apr 2016 07:44:32 +0300 Subject: HID: roccat: silence an uninitialized variable warning My static checker complains because we use "dev_id" before we check for errors so it could be uninitialized. Fix this by moving the error handling forward a couple lines. Signed-off-by: Dan Carpenter Signed-off-by: Jiri Kosina diff --git a/drivers/hid/hid-roccat.c b/drivers/hid/hid-roccat.c index 65c4ccfc..76d06cf 100644 --- a/drivers/hid/hid-roccat.c +++ b/drivers/hid/hid-roccat.c @@ -421,14 +421,13 @@ static int __init roccat_init(void) retval = alloc_chrdev_region(&dev_id, ROCCAT_FIRST_MINOR, ROCCAT_MAX_DEVICES, "roccat"); - - roccat_major = MAJOR(dev_id); - if (retval < 0) { pr_warn("can't get major number\n"); goto error; } + roccat_major = MAJOR(dev_id); + cdev_init(&roccat_cdev, &roccat_ops); retval = cdev_add(&roccat_cdev, dev_id, ROCCAT_MAX_DEVICES); -- cgit v0.10.2 From 6edac6fde59e231bd297ebcbc3d1bd395006cd1d Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Sat, 2 Apr 2016 07:45:01 +0300 Subject: HID: hidraw: silence an uninitialized variable warning My static checker complains that "devid" can be uninitialized if alloc_chrdev_region() fails. Fix this by moving the error hanling forward a couple lines. Signed-off-by: Dan Carpenter Signed-off-by: Jiri Kosina diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c index 9c2d7c2..4b981fd 100644 --- a/drivers/hid/hidraw.c +++ b/drivers/hid/hidraw.c @@ -587,14 +587,13 @@ int __init hidraw_init(void) result = alloc_chrdev_region(&dev_id, HIDRAW_FIRST_MINOR, HIDRAW_MAX_DEVICES, "hidraw"); - - hidraw_major = MAJOR(dev_id); - if (result < 0) { pr_warn("can't get major number\n"); goto out; } + hidraw_major = MAJOR(dev_id); + hidraw_class = class_create(THIS_MODULE, "hidraw"); if (IS_ERR(hidraw_class)) { result = PTR_ERR(hidraw_class); -- cgit v0.10.2 From 95d1c8951e5bd50bb89654a99a7012b1e75646bd Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Wed, 6 Apr 2016 10:19:58 -0700 Subject: HID: simplify implement() a bit The 'size' variable is not really needed, and we can also shift constant in the loop body when masking off existing bits. Also we do not have to use 64 bit calculations if we take an extra branch. [jkosina@suse.cz: fix a small error in changelog] Suggested-by: Doug Anderson Signed-off-by: Dmitry Torokhov Reviewed-by: Douglas Anderson Signed-off-by: Jiri Kosina diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index bdb8cc8..9985c0a 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); } -- cgit v0.10.2 From 282bf1fe6dca4b768d6bedc14aea1b82c36241c1 Mon Sep 17 00:00:00 2001 From: Trent Lloyd Date: Thu, 9 Jul 2015 13:38:50 +0800 Subject: HID: usbhid: quirks for Corsair RGB keyboard & mice (K70R, K95RGB, M65RGB, K70RGB, K65RGB) These devices feature multiple interfaces/endpoints: a legacy BIOS/boot interface (endpoint 0x81), as well as 2 corsair-specific keyboard interfaces (endpoint 0x82, 0x83 IN/0x03 OUT) and an RGB LED control interface (endpoint 0x84 IN/0x04 OUT) Because the extra 3 interfaces are not of subclass USB_INTERFACE_SUBCLASS_BOOT, HID_QUIRK_NOGET is not automatically set on them and a 10s timeout per-endpoint (30s per device) occurs initialising reports on boot. We configure HID_QUIRK_NO_INIT_REPORTS for these devices. Additionally the left-side G1-G18 macro keys on the K95RGB generate output on the un-opened 0x82/0x83 endpoints which causes the keyboard to stop responding waiting for this event to be collected. We enable HID_QUIRK_ALWAYS_POLL to prevent this situation from occurring. Signed-off-by: Trent Lloyd Tested-by: SUGNIAUX Wilfried Signed-off-by: Jiri Kosina diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index 5c0e43e..fa5b128 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h @@ -258,6 +258,13 @@ #define USB_VENDOR_ID_CORSAIR 0x1b1c #define USB_DEVICE_ID_CORSAIR_K90 0x1b02 +#define USB_VENDOR_ID_CORSAIR 0x1b1c +#define USB_DEVICE_ID_CORSAIR_K70R 0x1b09 +#define USB_DEVICE_ID_CORSAIR_K95RGB 0x1b11 +#define USB_DEVICE_ID_CORSAIR_M65RGB 0x1b12 +#define USB_DEVICE_ID_CORSAIR_K70RGB 0x1b13 +#define USB_DEVICE_ID_CORSAIR_K65RGB 0x1b17 + #define USB_VENDOR_ID_CREATIVELABS 0x041e #define USB_DEVICE_ID_PRODIKEYS_PCMIDI 0x2801 diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c index ed2f68e..0ffcaf9 100644 --- a/drivers/hid/usbhid/hid-quirks.c +++ b/drivers/hid/usbhid/hid-quirks.c @@ -71,6 +71,11 @@ static const struct hid_blacklist { { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_3AXIS_5BUTTON_STICK, HID_QUIRK_NOGET }, { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_AXIS_295, HID_QUIRK_NOGET }, { USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_PIXART_USB_OPTICAL_MOUSE, HID_QUIRK_ALWAYS_POLL }, + { USB_VENDOR_ID_CORSAIR, USB_DEVICE_ID_CORSAIR_K70R, HID_QUIRK_NO_INIT_REPORTS }, + { USB_VENDOR_ID_CORSAIR, USB_DEVICE_ID_CORSAIR_M65RGB, HID_QUIRK_NO_INIT_REPORTS }, + { USB_VENDOR_ID_CORSAIR, USB_DEVICE_ID_CORSAIR_K95RGB, HID_QUIRK_NO_INIT_REPORTS | HID_QUIRK_ALWAYS_POLL }, + { USB_VENDOR_ID_CORSAIR, USB_DEVICE_ID_CORSAIR_K70RGB, HID_QUIRK_NO_INIT_REPORTS }, + { USB_VENDOR_ID_CORSAIR, USB_DEVICE_ID_CORSAIR_K65RGB, HID_QUIRK_NO_INIT_REPORTS }, { USB_VENDOR_ID_DMI, USB_DEVICE_ID_DMI_ENC, HID_QUIRK_NOGET }, { USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_WIIU, HID_QUIRK_MULTI_INPUT }, { USB_VENDOR_ID_ELAN, HID_ANY_ID, HID_QUIRK_ALWAYS_POLL }, -- cgit v0.10.2