diff mbox series

HID: thrustmaster: fix memory leak in thrustmaster_interrupts()

Message ID 20250327231146.6388-1-qasdev00@gmail.com (mailing list archive)
State New
Delegated to: Jiri Kosina
Headers show
Series HID: thrustmaster: fix memory leak in thrustmaster_interrupts() | expand

Commit Message

Qasim Ijaz March 27, 2025, 11:11 p.m. UTC
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")
Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>
---
 drivers/hid/hid-thrustmaster.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Markus Elfring March 28, 2025, 10:56 a.m. UTC | #1
> In thrustmaster_interrupts(), the allocated send_buf is not
> freed if the usb_check_int_endpoints() check fails, leading
> to a memory leak.
…

I imagine that word wrapping can occasionally become a bit nicer
for text lines which may be longer than 59 characters.


…
> +++ b/drivers/hid/hid-thrustmaster.c
> @@ -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/cleanup.h#L144


Regards,
Markus
diff mbox series

Patch

diff --git a/drivers/hid/hid-thrustmaster.c b/drivers/hid/hid-thrustmaster.c
index 3b81468a1df2..0bf70664c35e 100644
--- a/drivers/hid/hid-thrustmaster.c
+++ b/drivers/hid/hid-thrustmaster.c
@@ -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;
 	}