[PATCH] HID: usbhid: free unsent raw output reports in usbhid_stop()

Dmitry Antipov <[email protected]>
Newsgroups org.kernel.vger.linux-input,org.kernel.vger.linux-usb
Message-ID <[email protected]>
When HID device is stalled or unexpectedly removed, there might be
an unsent (i.e. never passed via 'hid_submit_out()') output reports.
So free their raw buffers in 'usbhid_stop()' to avoid memory leaks.

Reported-by: [email protected]
Closes: https://syzkaller.appspot.com/bug?extid=e2c057ea576d2644e2be
Signed-off-by: Dmitry Antipov <[email protected]>
---
This is an (obvious?) companion patch for f7744fa16b9 ("HID: usbhid:
free raw_report buffers in usbhid_stop").
---
 drivers/hid/usbhid/hid-core.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 96b0181cf819..599a7566b825 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -1253,6 +1253,14 @@ static void usbhid_stop(struct hid_device *hid)
 		usbhid->ctrltail = (usbhid->ctrltail + 1) &
 			(HID_CONTROL_FIFO_SIZE - 1);
 	}
+
+	while (usbhid->outtail != usbhid->outhead) {
+		kfree(usbhid->out[usbhid->outtail].raw_report);
+		usbhid->out[usbhid->outtail].raw_report = NULL;
+
+		usbhid->outtail = (usbhid->outtail + 1) &
+			(HID_CONTROL_FIFO_SIZE - 1);
+	}
 	spin_unlock_irq(&usbhid->lock);
 
 	usb_kill_urb(usbhid->urbin);
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.