Skip to contentSkip to conversation

HID: thrustmaster: fix memory leak in thrustmaster_interrupts()

PATCH RESEND Superseded Qasim Ijaz 2 participants 2 messages Apr 6, 2025 – Apr 7, 2025

Subsystems (2)
lore
Share & tools
lore

Qasim Ijaz

author
#0 lore raw

PATCH RESEND 1/1 HID: thrustmaster: fix memory leak in thrustmaster_interrupts()

In thrustmaster_interrupts(), the allocated send_buf is not freed if the usb_check_int_endpoints() check fails, leading to a memory leak.

Fix this by ensuring send_buf is freed before returning in the error path.

Fixes 50420d7c79c3 ("HID: hid-thrustmaster: Fix warning in thrustmaster_probe by adding endpoint check")
---
 drivers/hid/hid-thrustmaster.c | 1 +
 1 file changed, 1 insertion(+)
drivers/hid/hid-thrustmaster.c +1 -0
index 3b81468a1df2..0bf70664c35e 100644
@@ -174,6 +174,7 @@ static void thrustmaster_interrupts(struct hid_device *hdev)
 	u8 ep_addr[2] = {b_ep, 0};
 
 	if (!usb_check_int_endpoints(usbif, ep_addr)) {
+		kfree(send_buf);
 		hid_err(hdev, "Unexpected non-int endpoint\n");
 		return;
 	}
Signature · 1 line
2.39.5
#1 lore raw
Quoted 3 lines

In thrustmaster_interrupts(), the allocated send_buf is not freed if the usb_check_int_endpoints() check fails, leading to a memory leak.

Will you get into the mood to make word wrapping occasionally a bit nicer for such text lines (which may be longer than 59 characters)?

…

drivers/hid/hid-thrustmaster.c static void thrustmaster_interrupts(struct hid_device *hdev) · line 180

Quoted 9 lines

+++ b/drivers/hid/hid-thrustmaster.c

drivers/hid/hid-thrustmaster.c +1 -0
@@ -174,6 +174,7 @@ static void thrustmaster_interrupts(struct hid_device *hdev)
 	u8 ep_addr[2] = {b_ep, 0};
 
 	if (!usb_check_int_endpoints(usbif, ep_addr)) {
+		kfree(send_buf);
 		hid_err(hdev, "Unexpected non-int endpoint\n");
 		return;
 	}

* You may avoid such repeated function calls by using another label instead.
https://wiki.sei.cmu.edu/confluence/display/c/MEM12-C.+Consider+using+a+goto+chain+when+leaving+a+function+on+error+when+using+and+releasing+resources#MEM12C.Considerusingagotochainwhenleavingafunctiononerrorwhenusingandreleasingresources-CompliantSolution(copy_process()fromLinuxkernel)

* How do you think about to benefit any more from the application of the attribute “__free”?
https://elixir.bootlin.com/linux/v6.14-rc6/source/include/linux/slab.h#L472

Regards,
Markus