Skip to content

Commit 37274b5

Browse files
glikelygregkh
authored andcommitted
HID: input: Fix devices that return multiple bytes in battery report
commit 4f57cac upstream. Some devices, particularly the 3DConnexion Spacemouse wireless 3D controllers, return more than just the battery capacity in the battery report. The Spacemouse devices return an additional byte with a device specific field. However, hidinput_query_battery_capacity() only requests a 2 byte transfer. When a spacemouse is connected via USB (direct wire, no wireless dongle) and it returns a 3 byte report instead of the assumed 2 byte battery report the larger transfer confuses and frightens the USB subsystem which chooses to ignore the transfer. Then after 2 seconds assume the device has stopped responding and reset it. This can be reproduced easily by using a wired connection with a wireless spacemouse. The Spacemouse will enter a loop of resetting every 2 seconds which can be observed in dmesg. This patch solves the problem by increasing the transfer request to 4 bytes instead of 2. The fix isn't particularly elegant, but it is simple and safe to backport to stable kernels. A further patch will follow to more elegantly handle battery reports that contain additional data. Signed-off-by: Grant Likely <grant.likely@secretlab.ca> Cc: Darren Hart <darren@dvhart.com> Cc: Jiri Kosina <jikos@kernel.org> Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com> Cc: stable@vger.kernel.org Tested-by: Darren Hart <dvhart@infradead.org> Signed-off-by: Jiri Kosina <jkosina@suse.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1874d3d commit 37274b5

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

drivers/hid/hid-input.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,13 @@ static int hidinput_query_battery_capacity(struct hid_device *dev)
362362
u8 *buf;
363363
int ret;
364364

365-
buf = kmalloc(2, GFP_KERNEL);
365+
buf = kmalloc(4, GFP_KERNEL);
366366
if (!buf)
367367
return -ENOMEM;
368368

369-
ret = hid_hw_raw_request(dev, dev->battery_report_id, buf, 2,
369+
ret = hid_hw_raw_request(dev, dev->battery_report_id, buf, 4,
370370
dev->battery_report_type, HID_REQ_GET_REPORT);
371-
if (ret != 2) {
371+
if (ret < 2) {
372372
kfree(buf);
373373
return -ENODATA;
374374
}

0 commit comments

Comments
 (0)