public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] media: radio-keene: fix memory leak in error path
@ 2025-11-26 19:04 Shaurya Rane
  2025-11-29 10:01 ` shaurya
  0 siblings, 1 reply; 2+ messages in thread
From: Shaurya Rane @ 2025-11-26 19:04 UTC (permalink / raw)
  To: Hans Verkuil, Mauro Carvalho Chehab, linux-media
  Cc: linux-kernel, linux-kernel-mentees, skhan, david.hunter.linux,
	khalid, Shaurya Rane, syzbot+a41b73dce23962a74c72

Fix a memory leak in usb_keene_probe(). The v4l2 control handler is
initialized and controls are added, but if v4l2_device_register() or
video_register_device() fails afterward, the handler was never freed,
leaking memory.

Add v4l2_ctrl_handler_free() call in the err_v4l2 error path to ensure
the control handler is properly freed for all error paths after it 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>
---
v3:
  - Put v4l2_ctrl_handler_free() in err_v4l2 label
    covering all error paths with a single call.
v2:
  - Simplified fix: call v4l2_ctrl_handler_free() inline before goto
    instead of adding a new error label.
---
 drivers/media/radio/radio-keene.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/radio/radio-keene.c b/drivers/media/radio/radio-keene.c
index f3b57f0cb1ec..c133305fd019 100644
--- a/drivers/media/radio/radio-keene.c
+++ b/drivers/media/radio/radio-keene.c
@@ -338,7 +338,6 @@ static int usb_keene_probe(struct usb_interface *intf,
 	if (hdl->error) {
 		retval = hdl->error;
 
-		v4l2_ctrl_handler_free(hdl);
 		goto err_v4l2;
 	}
 	retval = v4l2_device_register(&intf->dev, &radio->v4l2_dev);
@@ -384,6 +383,7 @@ static int usb_keene_probe(struct usb_interface *intf,
 err_vdev:
 	v4l2_device_unregister(&radio->v4l2_dev);
 err_v4l2:
+	v4l2_ctrl_handler_free(&radio->hdl);
 	kfree(radio->buffer);
 	kfree(radio);
 err:
-- 
2.34.1


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

* Re: [PATCH v3] media: radio-keene: fix memory leak in error path
  2025-11-26 19:04 [PATCH v3] media: radio-keene: fix memory leak in error path Shaurya Rane
@ 2025-11-29 10:01 ` shaurya
  0 siblings, 0 replies; 2+ messages in thread
From: shaurya @ 2025-11-29 10:01 UTC (permalink / raw)
  To: ssrane_b23
  Cc: hverkuil, khalid, linux-kernel, linux-media, mchehab,
	syzbot+a41b73dce23962a74c72

Pinging if missed


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

end of thread, other threads:[~2025-11-29 10:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-26 19:04 [PATCH v3] media: radio-keene: fix memory leak in error path Shaurya Rane
2025-11-29 10:01 ` shaurya

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