public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
* [PATCH] media: radio-keene: fix memory leak in error path
@ 2025-11-26  3:41 ssrane_b23
  2025-11-27 16:56 ` David Hunter
  0 siblings, 1 reply; 2+ messages in thread
From: ssrane_b23 @ 2025-11-26  3:41 UTC (permalink / raw)
  To: hverkuil
  Cc: mchehab, 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.

Fixes 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>
---
 drivers/media/radio/radio-keene.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/radio/radio-keene.c b/drivers/media/radio/radio-keene.c
index f3b57f0cb1ec..84916b5ebcb2 100644
--- a/drivers/media/radio/radio-keene.c
+++ b/drivers/media/radio/radio-keene.c
@@ -337,14 +337,12 @@ static int usb_keene_probe(struct usb_interface *intf,
 	radio->stereo = true;
 	if (hdl->error) {
 		retval = hdl->error;
-
-		v4l2_ctrl_handler_free(hdl);
-		goto err_v4l2;
+		goto err_hdl;
 	}
 	retval = v4l2_device_register(&intf->dev, &radio->v4l2_dev);
 	if (retval < 0) {
 		dev_err(&intf->dev, "couldn't register v4l2_device\n");
-		goto err_v4l2;
+		goto err_hdl;
 	}
 
 	mutex_init(&radio->lock);
@@ -383,6 +381,8 @@ static int usb_keene_probe(struct usb_interface *intf,
 
 err_vdev:
 	v4l2_device_unregister(&radio->v4l2_dev);
+err_hdl:
+	v4l2_ctrl_handler_free(&radio->hdl);
 err_v4l2:
 	kfree(radio->buffer);
 	kfree(radio);
-- 
2.34.1


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

* Re: [PATCH] media: radio-keene: fix memory leak in error path
  2025-11-26  3:41 [PATCH] media: radio-keene: fix memory leak in error path ssrane_b23
@ 2025-11-27 16:56 ` David Hunter
  0 siblings, 0 replies; 2+ messages in thread
From: David Hunter @ 2025-11-27 16:56 UTC (permalink / raw)
  To: ssrane_b23, hverkuil
  Cc: mchehab, linux-media, linux-kernel, skhan, linux-kernel-mentees,
	khalid, syzbot+a41b73dce23962a74c72

On 11/25/25 22:41, ssrane_b23@ee.vjti.ac.in wrote:
> From: Shaurya Rane <ssrane_b23@ee.vjti.ac.in>

Try not to put an empty line before you are done with the meta-data for
the patch. When you put an empty line, whatever is after the empty line
comes through in the message.


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

end of thread, other threads:[~2025-11-27 16:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-26  3:41 [PATCH] media: radio-keene: fix memory leak in error path ssrane_b23
2025-11-27 16:56 ` David Hunter

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