public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
* [PATCH v2] media: radio-keene: fix memory leak in error path
@ 2025-11-26  6:30 ssrane_b23
  2025-11-26 17:46 ` Abdun Nihaal
  0 siblings, 1 reply; 2+ messages in thread
From: ssrane_b23 @ 2025-11-26  6:30 UTC (permalink / raw)
  To: Hans Verkuil, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, skhan, linux-kernel-mentees,
	david.hunter.linux, khalid, Shaurya Rane,
	syzbot+a41b73dce23962a74c72

From: Shaurya Rane <ssrane_b23@ee.vjti.ac.in>

Fix a memory leak in usb_keene_probe() when v4l2_device_register()
fails. The v4l2 control handler was initialized and controls were
added, but if v4l2_device_register() failed, the handler was never
freed, leaking the allocated memory for the handler buckets and
control structures.

Consolidate the error handling by adding an err_hdl label that
ensures v4l2_ctrl_handler_free() is called for all error paths
after the handler is initialized.

Reported-by: syzbot+a41b73dce23962a74c72@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=a41b73dce23962a74c72
Fixes: 1bf20c3a0c61 ("[media] radio-keene: add a driver for the Keene FM Transmitter")
Signed-off-by: Shaurya Rane <ssrane_b23@ee.vjti.ac.in>
---
v2:
  - Simplified fix: call v4l2_ctrl_handler_free() inline before goto
    instead of adding a new error label, avoiding unused label warning
    reported by Media CI.
---
 drivers/media/radio/radio-keene.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/radio/radio-keene.c b/drivers/media/radio/radio-keene.c
index f3b57f0cb1ec..4a203e958a4f 100644
--- a/drivers/media/radio/radio-keene.c
+++ b/drivers/media/radio/radio-keene.c
@@ -344,6 +344,7 @@ static int usb_keene_probe(struct usb_interface *intf,
 	retval = v4l2_device_register(&intf->dev, &radio->v4l2_dev);
 	if (retval < 0) {
 		dev_err(&intf->dev, "couldn't register v4l2_device\n");
+		v4l2_ctrl_handler_free(hdl);
 		goto err_v4l2;
 	}
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] media: radio-keene: fix memory leak in error path
  2025-11-26  6:30 [PATCH v2] media: radio-keene: fix memory leak in error path ssrane_b23
@ 2025-11-26 17:46 ` Abdun Nihaal
  0 siblings, 0 replies; 2+ messages in thread
From: Abdun Nihaal @ 2025-11-26 17:46 UTC (permalink / raw)
  To: ssrane_b23
  Cc: Hans Verkuil, Mauro Carvalho Chehab, linux-media, linux-kernel,
	skhan, linux-kernel-mentees, david.hunter.linux, khalid,
	syzbot+a41b73dce23962a74c72

On Wed, Nov 26, 2025 at 12:00:00PM +0530, ssrane_b23@ee.vjti.ac.in wrote:
> Fix a memory leak in usb_keene_probe() when v4l2_device_register()
> fails. The v4l2 control handler was initialized and controls were
> added, but if v4l2_device_register() failed, the handler was never
> freed, leaking the allocated memory for the handler buckets and
> control structures.
> 
> Consolidate the error handling by adding an err_hdl label that
> ensures v4l2_ctrl_handler_free() is called for all error paths
> after the handler is initialized.
> 
> ---
> v2:
>   - Simplified fix: call v4l2_ctrl_handler_free() inline before goto
>     instead of adding a new error label, avoiding unused label warning
>     reported by Media CI.

v4l2_ctrl_handler_free() has to be called in the last error path also
(the one after the v4l2_device_register() call).

Your v1 patch was correct and also better because it avoided repeated
calls to v4l2_ctrl_handler_free() in different error paths.

To fix the unused label warning just use err_v4l2 itself instead of
introducing err_hdl, because both error path that goes to err_v4l2
needs to call v4l2_ctrl_handler_free() to fix the memory leak.

Regards,
Nihaal

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-11-26 17:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-26  6:30 [PATCH v2] media: radio-keene: fix memory leak in error path ssrane_b23
2025-11-26 17:46 ` Abdun Nihaal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox