Skip to content

Commit cdcba02

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid: HID: add quirk entry for no-name keyboard (0x13ba/0x0017) HID: fix hid_device_id for cross compiling HID: sync on deleted io_retry timer in usbhid driver HID: fix oops during suspend of unbound HID devices
2 parents 53387b0 + fa157bd commit cdcba02

7 files changed

Lines changed: 51 additions & 18 deletions

File tree

‎drivers/hid/hid-core.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,7 @@ static const struct hid_device_id hid_blacklist[] = {
12631263
{ HID_USB_DEVICE(USB_VENDOR_ID_DELL, USB_DEVICE_ID_DELL_W7658) },
12641264
{ HID_USB_DEVICE(USB_VENDOR_ID_DELL, USB_DEVICE_ID_DELL_SK8115) },
12651265
{ HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
1266+
{ HID_USB_DEVICE(USB_VENDOR_ID_GENERIC_13BA, USB_DEVICE_ID_GENERIC_13BA_KBD_MOUSE) },
12661267
{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
12671268
{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
12681269
{ HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },

‎drivers/hid/hid-dell.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static int dell_probe(struct hid_device *hdev, const struct hid_device_id *id)
4848
static const struct hid_device_id dell_devices[] = {
4949
{ HID_USB_DEVICE(USB_VENDOR_ID_DELL, USB_DEVICE_ID_DELL_W7658) },
5050
{ HID_USB_DEVICE(USB_VENDOR_ID_DELL, USB_DEVICE_ID_DELL_SK8115) },
51+
{ HID_USB_DEVICE(USB_VENDOR_ID_GENERIC_13BA, USB_DEVICE_ID_GENERIC_13BA_KBD_MOUSE) },
5152
{ }
5253
};
5354
MODULE_DEVICE_TABLE(hid, dell_devices);

‎drivers/hid/hid-ids.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@
163163

164164
#define USB_VENDOR_ID_GENERAL_TOUCH 0x0dfc
165165

166+
#define USB_VENDOR_ID_GENERIC_13BA 0x13ba
167+
#define USB_DEVICE_ID_GENERIC_13BA_KBD_MOUSE 0x0017
168+
166169
#define USB_VENDOR_ID_GLAB 0x06c2
167170
#define USB_DEVICE_ID_4_PHIDGETSERVO_30 0x0038
168171
#define USB_DEVICE_ID_1_PHIDGETSERVO_30 0x0039

‎drivers/hid/usbhid/hid-core.c‎

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/kernel.h>
2121
#include <linux/list.h>
2222
#include <linux/mm.h>
23+
#include <linux/mutex.h>
2324
#include <linux/smp_lock.h>
2425
#include <linux/spinlock.h>
2526
#include <asm/unaligned.h>
@@ -776,21 +777,10 @@ static int usbhid_start(struct hid_device *hid)
776777
struct usb_interface *intf = to_usb_interface(hid->dev.parent);
777778
struct usb_host_interface *interface = intf->cur_altsetting;
778779
struct usb_device *dev = interface_to_usbdev(intf);
779-
struct usbhid_device *usbhid;
780+
struct usbhid_device *usbhid = hid->driver_data;
780781
unsigned int n, insize = 0;
781782
int ret;
782783

783-
WARN_ON(hid->driver_data);
784-
785-
usbhid = kzalloc(sizeof(struct usbhid_device), GFP_KERNEL);
786-
if (usbhid == NULL) {
787-
ret = -ENOMEM;
788-
goto err;
789-
}
790-
791-
hid->driver_data = usbhid;
792-
usbhid->hid = hid;
793-
794784
usbhid->bufsize = HID_MIN_BUFFER_SIZE;
795785
hid_find_max_report(hid, HID_INPUT_REPORT, &usbhid->bufsize);
796786
hid_find_max_report(hid, HID_OUTPUT_REPORT, &usbhid->bufsize);
@@ -804,6 +794,7 @@ static int usbhid_start(struct hid_device *hid)
804794
if (insize > HID_MAX_BUFFER_SIZE)
805795
insize = HID_MAX_BUFFER_SIZE;
806796

797+
mutex_lock(&usbhid->setup);
807798
if (hid_alloc_buffers(dev, hid)) {
808799
ret = -ENOMEM;
809800
goto fail;
@@ -888,15 +879,17 @@ static int usbhid_start(struct hid_device *hid)
888879
usbhid_init_reports(hid);
889880
hid_dump_device(hid);
890881

882+
set_bit(HID_STARTED, &usbhid->iofl);
883+
mutex_unlock(&usbhid->setup);
884+
891885
return 0;
892886

893887
fail:
894888
usb_free_urb(usbhid->urbin);
895889
usb_free_urb(usbhid->urbout);
896890
usb_free_urb(usbhid->urbctrl);
897891
hid_free_buffers(dev, hid);
898-
kfree(usbhid);
899-
err:
892+
mutex_unlock(&usbhid->setup);
900893
return ret;
901894
}
902895

@@ -907,6 +900,8 @@ static void usbhid_stop(struct hid_device *hid)
907900
if (WARN_ON(!usbhid))
908901
return;
909902

903+
mutex_lock(&usbhid->setup);
904+
clear_bit(HID_STARTED, &usbhid->iofl);
910905
spin_lock_irq(&usbhid->inlock); /* Sync with error handler */
911906
set_bit(HID_DISCONNECTED, &usbhid->iofl);
912907
spin_unlock_irq(&usbhid->inlock);
@@ -931,8 +926,7 @@ static void usbhid_stop(struct hid_device *hid)
931926
usb_free_urb(usbhid->urbout);
932927

933928
hid_free_buffers(hid_to_usb_dev(hid), hid);
934-
kfree(usbhid);
935-
hid->driver_data = NULL;
929+
mutex_unlock(&usbhid->setup);
936930
}
937931

938932
static struct hid_ll_driver usb_hid_driver = {
@@ -947,6 +941,7 @@ static struct hid_ll_driver usb_hid_driver = {
947941
static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id)
948942
{
949943
struct usb_device *dev = interface_to_usbdev(intf);
944+
struct usbhid_device *usbhid;
950945
struct hid_device *hid;
951946
size_t len;
952947
int ret;
@@ -1000,14 +995,26 @@ static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id)
1000995
if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0)
1001996
hid->uniq[0] = 0;
1002997

998+
usbhid = kzalloc(sizeof(*usbhid), GFP_KERNEL);
999+
if (usbhid == NULL) {
1000+
ret = -ENOMEM;
1001+
goto err;
1002+
}
1003+
1004+
hid->driver_data = usbhid;
1005+
usbhid->hid = hid;
1006+
mutex_init(&usbhid->setup); /* needed on suspend/resume */
1007+
10031008
ret = hid_add_device(hid);
10041009
if (ret) {
10051010
if (ret != -ENODEV)
10061011
dev_err(&intf->dev, "can't add hid device: %d\n", ret);
1007-
goto err;
1012+
goto err_free;
10081013
}
10091014

10101015
return 0;
1016+
err_free:
1017+
kfree(usbhid);
10111018
err:
10121019
hid_destroy_device(hid);
10131020
return ret;
@@ -1016,23 +1023,33 @@ static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id)
10161023
static void hid_disconnect(struct usb_interface *intf)
10171024
{
10181025
struct hid_device *hid = usb_get_intfdata(intf);
1026+
struct usbhid_device *usbhid;
10191027

10201028
if (WARN_ON(!hid))
10211029
return;
10221030

1031+
usbhid = hid->driver_data;
10231032
hid_destroy_device(hid);
1033+
kfree(usbhid);
10241034
}
10251035

10261036
static int hid_suspend(struct usb_interface *intf, pm_message_t message)
10271037
{
10281038
struct hid_device *hid = usb_get_intfdata (intf);
10291039
struct usbhid_device *usbhid = hid->driver_data;
10301040

1041+
mutex_lock(&usbhid->setup);
1042+
if (!test_bit(HID_STARTED, &usbhid->iofl)) {
1043+
mutex_unlock(&usbhid->setup);
1044+
return 0;
1045+
}
1046+
10311047
spin_lock_irq(&usbhid->inlock); /* Sync with error handler */
10321048
set_bit(HID_SUSPENDED, &usbhid->iofl);
10331049
spin_unlock_irq(&usbhid->inlock);
1034-
del_timer(&usbhid->io_retry);
1050+
del_timer_sync(&usbhid->io_retry);
10351051
usb_kill_urb(usbhid->urbin);
1052+
mutex_unlock(&usbhid->setup);
10361053
dev_dbg(&intf->dev, "suspend\n");
10371054
return 0;
10381055
}
@@ -1043,9 +1060,16 @@ static int hid_resume(struct usb_interface *intf)
10431060
struct usbhid_device *usbhid = hid->driver_data;
10441061
int status;
10451062

1063+
mutex_lock(&usbhid->setup);
1064+
if (!test_bit(HID_STARTED, &usbhid->iofl)) {
1065+
mutex_unlock(&usbhid->setup);
1066+
return 0;
1067+
}
1068+
10461069
clear_bit(HID_SUSPENDED, &usbhid->iofl);
10471070
usbhid->retry_delay = 0;
10481071
status = hid_start_in(hid);
1072+
mutex_unlock(&usbhid->setup);
10491073
dev_dbg(&intf->dev, "resume status %d\n", status);
10501074
return status;
10511075
}

‎drivers/hid/usbhid/usbhid.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/types.h>
2828
#include <linux/slab.h>
2929
#include <linux/list.h>
30+
#include <linux/mutex.h>
3031
#include <linux/timer.h>
3132
#include <linux/wait.h>
3233
#include <linux/workqueue.h>
@@ -73,6 +74,7 @@ struct usbhid_device {
7374
dma_addr_t outbuf_dma; /* Output buffer dma */
7475
spinlock_t outlock; /* Output fifo spinlock */
7576

77+
struct mutex setup;
7678
unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */
7779
struct timer_list io_retry; /* Retry timer */
7880
unsigned long stop_retry; /* Time to give up, in jiffies */

‎include/linux/hid.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ struct hid_output_fifo {
410410
#define HID_SUSPENDED 5
411411
#define HID_CLEAR_HALT 6
412412
#define HID_DISCONNECTED 7
413+
#define HID_STARTED 8
413414

414415
struct hid_input {
415416
struct list_head list;

‎include/linux/mod_devicetable.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ struct usb_device_id {
135135

136136
struct hid_device_id {
137137
__u16 bus;
138+
__u16 pad1;
138139
__u32 vendor;
139140
__u32 product;
140141
kernel_ulong_t driver_data

0 commit comments

Comments
 (0)