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

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid

Pull HID fixes from Jiri Kosina:

- regression fix / revert of a commit that intended to reduce probing
delay by ~50ms, but introduced a race that causes quite a few devices
not to enumerate, or get stuck on first IRQ

- buffer overflow fix in hiddev, from Peilin Ye

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid:
Revert "HID: usbhid: do not sleep when opening device"
HID: hiddev: Fix slab-out-of-bounds write in hiddev_ioctl_usage()
HID: quirks: Always poll three more Lenovo PixArt mice
HID: i2c-hid: Always sleep 60ms after I2C_HID_PWR_ON commands
HID: macally: Constify macally_id_table
HID: cougar: Constify cougar_id_table

+49 -42
+1 -1
drivers/hid/hid-cougar.c
··· 321 321 }; 322 322 module_param_cb(g6_is_space, &cougar_g6_is_space_ops, &g6_is_space, 0644); 323 323 324 - static struct hid_device_id cougar_id_table[] = { 324 + static const struct hid_device_id cougar_id_table[] = { 325 325 { HID_USB_DEVICE(USB_VENDOR_ID_SOLID_YEAR, 326 326 USB_DEVICE_ID_COUGAR_500K_GAMING_KEYBOARD) }, 327 327 { HID_USB_DEVICE(USB_VENDOR_ID_SOLID_YEAR,
+3
drivers/hid/hid-ids.h
··· 728 728 #define USB_DEVICE_ID_LENOVO_TPPRODOCK 0x6067 729 729 #define USB_DEVICE_ID_LENOVO_X1_COVER 0x6085 730 730 #define USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_608D 0x608d 731 + #define USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_6019 0x6019 732 + #define USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_602E 0x602e 733 + #define USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_6093 0x6093 731 734 732 735 #define USB_VENDOR_ID_LG 0x1fd2 733 736 #define USB_DEVICE_ID_LG_MULTITOUCH 0x0064
+1 -1
drivers/hid/hid-macally.c
··· 29 29 return rdesc; 30 30 } 31 31 32 - static struct hid_device_id macally_id_table[] = { 32 + static const struct hid_device_id macally_id_table[] = { 33 33 { HID_USB_DEVICE(USB_VENDOR_ID_SOLID_YEAR, 34 34 USB_DEVICE_ID_MACALLY_IKEY_KEYBOARD) }, 35 35 { }
+3
drivers/hid/hid-quirks.c
··· 105 105 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M406XE), HID_QUIRK_MULTI_INPUT }, 106 106 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_PIXART_USB_OPTICAL_MOUSE_ID2), HID_QUIRK_ALWAYS_POLL }, 107 107 { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_608D), HID_QUIRK_ALWAYS_POLL }, 108 + { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_6019), HID_QUIRK_ALWAYS_POLL }, 109 + { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_602E), HID_QUIRK_ALWAYS_POLL }, 110 + { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_6093), HID_QUIRK_ALWAYS_POLL }, 108 111 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_C007), HID_QUIRK_ALWAYS_POLL }, 109 112 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_C077), HID_QUIRK_ALWAYS_POLL }, 110 113 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_KEYBOARD_G710_PLUS), HID_QUIRK_NOGET },
+13 -9
drivers/hid/i2c-hid/i2c-hid-core.c
··· 420 420 dev_err(&client->dev, "failed to change power setting.\n"); 421 421 422 422 set_pwr_exit: 423 + 424 + /* 425 + * The HID over I2C specification states that if a DEVICE needs time 426 + * after the PWR_ON request, it should utilise CLOCK stretching. 427 + * However, it has been observered that the Windows driver provides a 428 + * 1ms sleep between the PWR_ON and RESET requests. 429 + * According to Goodix Windows even waits 60 ms after (other?) 430 + * PWR_ON requests. Testing has confirmed that several devices 431 + * will not work properly without a delay after a PWR_ON request. 432 + */ 433 + if (!ret && power_state == I2C_HID_PWR_ON) 434 + msleep(60); 435 + 423 436 return ret; 424 437 } 425 438 ··· 453 440 ret = i2c_hid_set_power(client, I2C_HID_PWR_ON); 454 441 if (ret) 455 442 goto out_unlock; 456 - 457 - /* 458 - * The HID over I2C specification states that if a DEVICE needs time 459 - * after the PWR_ON request, it should utilise CLOCK stretching. 460 - * However, it has been observered that the Windows driver provides a 461 - * 1ms sleep between the PWR_ON and RESET requests and that some devices 462 - * rely on this. 463 - */ 464 - usleep_range(1000, 5000); 465 443 466 444 i2c_hid_dbg(ihid, "resetting...\n"); 467 445
+24 -29
drivers/hid/usbhid/hid-core.c
··· 26 26 #include <linux/wait.h> 27 27 #include <linux/workqueue.h> 28 28 #include <linux/string.h> 29 - #include <linux/timekeeping.h> 30 29 31 30 #include <linux/usb.h> 32 31 ··· 95 96 set_bit(HID_NO_BANDWIDTH, &usbhid->iofl); 96 97 } else { 97 98 clear_bit(HID_NO_BANDWIDTH, &usbhid->iofl); 98 - 99 - if (test_bit(HID_RESUME_RUNNING, &usbhid->iofl)) { 100 - /* 101 - * In case events are generated while nobody was 102 - * listening, some are released when the device 103 - * is re-opened. Wait 50 msec for the queue to 104 - * empty before allowing events to go through 105 - * hid. 106 - */ 107 - usbhid->input_start_time = 108 - ktime_add_ms(ktime_get_coarse(), 50); 109 - } 110 99 } 111 100 } 112 101 spin_unlock_irqrestore(&usbhid->lock, flags); ··· 280 293 if (!test_bit(HID_OPENED, &usbhid->iofl)) 281 294 break; 282 295 usbhid_mark_busy(usbhid); 283 - if (test_bit(HID_RESUME_RUNNING, &usbhid->iofl)) { 284 - if (ktime_before(ktime_get_coarse(), 285 - usbhid->input_start_time)) 286 - break; 287 - clear_bit(HID_RESUME_RUNNING, &usbhid->iofl); 296 + if (!test_bit(HID_RESUME_RUNNING, &usbhid->iofl)) { 297 + hid_input_report(urb->context, HID_INPUT_REPORT, 298 + urb->transfer_buffer, 299 + urb->actual_length, 1); 300 + /* 301 + * autosuspend refused while keys are pressed 302 + * because most keyboards don't wake up when 303 + * a key is released 304 + */ 305 + if (hid_check_keys_pressed(hid)) 306 + set_bit(HID_KEYS_PRESSED, &usbhid->iofl); 307 + else 308 + clear_bit(HID_KEYS_PRESSED, &usbhid->iofl); 288 309 } 289 - hid_input_report(urb->context, HID_INPUT_REPORT, 290 - urb->transfer_buffer, urb->actual_length, 1); 291 - /* 292 - * autosuspend refused while keys are pressed 293 - * because most keyboards don't wake up when 294 - * a key is released 295 - */ 296 - if (hid_check_keys_pressed(hid)) 297 - set_bit(HID_KEYS_PRESSED, &usbhid->iofl); 298 - else 299 - clear_bit(HID_KEYS_PRESSED, &usbhid->iofl); 300 310 break; 301 311 case -EPIPE: /* stall */ 302 312 usbhid_mark_busy(usbhid); ··· 719 735 } 720 736 721 737 usb_autopm_put_interface(usbhid->intf); 738 + 739 + /* 740 + * In case events are generated while nobody was listening, 741 + * some are released when the device is re-opened. 742 + * Wait 50 msec for the queue to empty before allowing events 743 + * to go through hid. 744 + */ 745 + if (res == 0) 746 + msleep(50); 747 + 748 + clear_bit(HID_RESUME_RUNNING, &usbhid->iofl); 722 749 723 750 Done: 724 751 mutex_unlock(&usbhid->mutex);
+4
drivers/hid/usbhid/hiddev.c
··· 519 519 520 520 switch (cmd) { 521 521 case HIDIOCGUSAGE: 522 + if (uref->usage_index >= field->report_count) 523 + goto inval; 522 524 uref->value = field->value[uref->usage_index]; 523 525 if (copy_to_user(user_arg, uref, sizeof(*uref))) 524 526 goto fault; 525 527 goto goodreturn; 526 528 527 529 case HIDIOCSUSAGE: 530 + if (uref->usage_index >= field->report_count) 531 + goto inval; 528 532 field->value[uref->usage_index] = uref->value; 529 533 goto goodreturn; 530 534
-2
drivers/hid/usbhid/usbhid.h
··· 13 13 14 14 #include <linux/types.h> 15 15 #include <linux/slab.h> 16 - #include <linux/ktime.h> 17 16 #include <linux/list.h> 18 17 #include <linux/mutex.h> 19 18 #include <linux/timer.h> ··· 83 84 struct mutex mutex; /* start/stop/open/close */ 84 85 spinlock_t lock; /* fifo spinlock */ 85 86 unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */ 86 - ktime_t input_start_time; /* When to start handling input */ 87 87 struct timer_list io_retry; /* Retry timer */ 88 88 unsigned long stop_retry; /* Time to give up, in jiffies */ 89 89 unsigned int retry_delay; /* Delay length in ms */