Skip to contentSkip to conversation

HID: usbhid: fix memleak for ctrl or out raw_report

PATCH In review [email protected] 1 participant 2 messages Nov 17, 2020 – Nov 24, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: usbhid: fix memleak for ctrl or out raw_report

From: Zqiang <[email protected]>

When the usb device disconnect, usbhid_stop function be called, if ctrl or out's raw_report exists, need to be free.

---
 drivers/hid/usbhid/hid-core.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/hid/usbhid/hid-core.c +8 -0
index 17a29ee0ac6c..f8a49f8d4015 100644
@@ -1209,6 +1209,7 @@ static int usbhid_start(struct hid_device *hid)
 static void usbhid_stop(struct hid_device *hid)
 {
 	struct usbhid_device *usbhid = hid->driver_data;
+	int index;
 
 	if (WARN_ON(!usbhid))
 		return;
@@ -1232,6 +1233,13 @@ static void usbhid_stop(struct hid_device *hid)
 
 	hid->claimed = 0;
 
+	for (index = 0; index < HID_CONTROL_FIFO_SIZE; index++) {
+		if (usbhid->ctrl[index].raw_report)
+			kfree(usbhid->ctrl[index].raw_report);
+		if (usbhid->out[index].raw_report)
+			kfree(usbhid->out[index].raw_report);
+	}
+
 	usb_free_urb(usbhid->urbin);
 	usb_free_urb(usbhid->urbctrl);
 	usb_free_urb(usbhid->urbout);
Signature · 1 line
2.17.1
#1 lore raw

________________________________________
发件人: Zhang, Qiang <[email protected]>
发送时间: 2020年11月17日 13:49
收件人: [email protected]; [email protected] 抄送: [email protected]; [email protected] 主题: [PATCH] HID: usbhid: fix memleak for ctrl or out raw_report

From: Zqiang <[email protected]>

When the usb device disconnect, usbhid_stop function be called, if ctrl or out's raw_report exists, need to be free.

---
 drivers/hid/usbhid/hid-core.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/hid/usbhid/hid-core.c +8 -0
index 17a29ee0ac6c..f8a49f8d4015 100644
@@ -1209,6 +1209,7 @@ static int usbhid_start(struct hid_device *hid)
 static void usbhid_stop(struct hid_device *hid)
 {
        struct usbhid_device *usbhid = hid->driver_data;
+       int index;
 
        if (WARN_ON(!usbhid))
                return;
@@ -1232,6 +1233,13 @@ static void usbhid_stop(struct hid_device *hid)
 
        hid->claimed = 0;
 
+       for (index = 0; index < HID_CONTROL_FIFO_SIZE; index++) {
+               if (usbhid->ctrl[index].raw_report)
+                       kfree(usbhid->ctrl[index].raw_report);
+               if (usbhid->out[index].raw_report)
+                       kfree(usbhid->out[index].raw_report);
+       }
+
        usb_free_urb(usbhid->urbin);
        usb_free_urb(usbhid->urbctrl);
        usb_free_urb(usbhid->urbout);

--
2.17.1