aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Daughtridge <kevin@kdau.com>2012-09-20 15:00:32 -0400
committerJiri Kosina <jkosina@suse.cz>2012-10-01 04:09:26 -0400
commit86e6b77eb7cf9ca2e9c7092b4dfd588f0a3307b6 (patch)
treed00ef9d1f11bae93c5e809246f8eae156d74b1ed
parent4cc9834518efed3b69d3a8ff3bd162e089f68d34 (diff)
HID: keep dev_rdesc unmodified and use it for comparisons
The dev_rdesc member of the hid_device structure is meant to store the original report descriptor received from the device, but it is currently passed to any report_fixup method before it is copied to the rdesc member. This patch uses a temporary buffer to shield dev_rdesc from the side effects of many HID drivers' report_fixup implementations. usbhid's hid_post_reset checks the report descriptor currently returned by the device against a descriptor that may have been modified by a driver's report_fixup method. That leaves some devices nonfunctional after a resume, with a "reset_resume error 1" reported. This patch checks the new descriptor against the unmodified dev_rdesc instead and uses the original, instead of modified, report size. BugLink: http://bugs.launchpad.net/bugs/1049623 Signed-off-by: Kevin Daughtridge <kevin@kdau.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r--drivers/hid/hid-core.c16
-rw-r--r--drivers/hid/usbhid/hid-core.c6
2 files changed, 16 insertions, 6 deletions
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index dd679a582c2..ec917690c26 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -757,6 +757,7 @@ int hid_open_report(struct hid_device *device)
757 struct hid_item item; 757 struct hid_item item;
758 unsigned int size; 758 unsigned int size;
759 __u8 *start; 759 __u8 *start;
760 __u8 *buf;
760 __u8 *end; 761 __u8 *end;
761 int ret; 762 int ret;
762 static int (*dispatch_type[])(struct hid_parser *parser, 763 static int (*dispatch_type[])(struct hid_parser *parser,
@@ -775,12 +776,21 @@ int hid_open_report(struct hid_device *device)
775 return -ENODEV; 776 return -ENODEV;
776 size = device->dev_rsize; 777 size = device->dev_rsize;
777 778
779 buf = kmemdup(start, size, GFP_KERNEL);
780 if (buf == NULL)
781 return -ENOMEM;
782
778 if (device->driver->report_fixup) 783 if (device->driver->report_fixup)
779 start = device->driver->report_fixup(device, start, &size); 784 start = device->driver->report_fixup(device, buf, &size);
785 else
786 start = buf;
780 787
781 device->rdesc = kmemdup(start, size, GFP_KERNEL); 788 start = kmemdup(start, size, GFP_KERNEL);
782 if (device->rdesc == NULL) 789 kfree(buf);
790 if (start == NULL)
783 return -ENOMEM; 791 return -ENOMEM;
792
793 device->rdesc = start;
784 device->rsize = size; 794 device->rsize = size;
785 795
786 parser = vzalloc(sizeof(struct hid_parser)); 796 parser = vzalloc(sizeof(struct hid_parser));
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index dedd8e4e5c6..8e0c4bf94eb 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -1415,20 +1415,20 @@ static int hid_post_reset(struct usb_interface *intf)
1415 * configuration descriptors passed, we already know that 1415 * configuration descriptors passed, we already know that
1416 * the size of the HID report descriptor has not changed. 1416 * the size of the HID report descriptor has not changed.
1417 */ 1417 */
1418 rdesc = kmalloc(hid->rsize, GFP_KERNEL); 1418 rdesc = kmalloc(hid->dev_rsize, GFP_KERNEL);
1419 if (!rdesc) { 1419 if (!rdesc) {
1420 dbg_hid("couldn't allocate rdesc memory (post_reset)\n"); 1420 dbg_hid("couldn't allocate rdesc memory (post_reset)\n");
1421 return 1; 1421 return 1;
1422 } 1422 }
1423 status = hid_get_class_descriptor(dev, 1423 status = hid_get_class_descriptor(dev,
1424 interface->desc.bInterfaceNumber, 1424 interface->desc.bInterfaceNumber,
1425 HID_DT_REPORT, rdesc, hid->rsize); 1425 HID_DT_REPORT, rdesc, hid->dev_rsize);
1426 if (status < 0) { 1426 if (status < 0) {
1427 dbg_hid("reading report descriptor failed (post_reset)\n"); 1427 dbg_hid("reading report descriptor failed (post_reset)\n");
1428 kfree(rdesc); 1428 kfree(rdesc);
1429 return 1; 1429 return 1;
1430 } 1430 }
1431 status = memcmp(rdesc, hid->rdesc, hid->rsize); 1431 status = memcmp(rdesc, hid->dev_rdesc, hid->dev_rsize);
1432 kfree(rdesc); 1432 kfree(rdesc);
1433 if (status != 0) { 1433 if (status != 0) {
1434 dbg_hid("report descriptor changed\n"); 1434 dbg_hid("report descriptor changed\n");