* [PATCH] HID: thrustmaster: fix memory leak in thrustmaster_interrupts()
@ 2025-03-27 23:11 Qasim Ijaz
2025-03-28 10:56 ` Markus Elfring
2025-04-24 9:48 ` Jiri Kosina
0 siblings, 2 replies; 3+ messages in thread
From: Qasim Ijaz @ 2025-03-27 23:11 UTC (permalink / raw)
To: jikos, bentiss, mcoquelin.stm32, alexandre.torgue
Cc: linux-input, linux-stm32, linux-arm-kernel, linux-kernel
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(+)
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;
}
--
2.39.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] HID: thrustmaster: fix memory leak in thrustmaster_interrupts()
2025-03-27 23:11 [PATCH] HID: thrustmaster: fix memory leak in thrustmaster_interrupts() Qasim Ijaz
@ 2025-03-28 10:56 ` Markus Elfring
2025-04-24 9:48 ` Jiri Kosina
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2025-03-28 10:56 UTC (permalink / raw)
To: Qasim Ijaz, linux-input, linux-arm-kernel, linux-stm32
Cc: LKML, Alexandre Torgue, Benjamin Tissoires, Jiri Kosina,
Maxime Coquelin
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] HID: thrustmaster: fix memory leak in thrustmaster_interrupts()
2025-03-27 23:11 [PATCH] HID: thrustmaster: fix memory leak in thrustmaster_interrupts() Qasim Ijaz
2025-03-28 10:56 ` Markus Elfring
@ 2025-04-24 9:48 ` Jiri Kosina
1 sibling, 0 replies; 3+ messages in thread
From: Jiri Kosina @ 2025-04-24 9:48 UTC (permalink / raw)
To: Qasim Ijaz
Cc: bentiss, mcoquelin.stm32, alexandre.torgue, linux-input,
linux-stm32, linux-arm-kernel, linux-kernel
On Thu, 27 Mar 2025, Qasim Ijaz wrote:
> 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>
Applied, thanks.
--
Jiri Kosina
SUSE Labs
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-24 9:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-27 23:11 [PATCH] HID: thrustmaster: fix memory leak in thrustmaster_interrupts() Qasim Ijaz
2025-03-28 10:56 ` Markus Elfring
2025-04-24 9:48 ` Jiri Kosina
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).