All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] media: hi846: Fix memleak in hi846_init_controls()
@ 2023-03-27 11:58 Wei Chen
  2023-03-27 12:20 ` Martin Kepplinger
  0 siblings, 1 reply; 2+ messages in thread
From: Wei Chen @ 2023-03-27 11:58 UTC (permalink / raw)
  To: martink; +Cc: mchehab, linux-media, linux-kernel, Wei Chen

hi846_init_controls doesn't clean the allocated ctrl_hdlr
in case there is a failure, which causes memleak. Add
v4l2_ctrl_handler_free to free the resource properly.

Fixes: e8c0882685f9 ("media: i2c: add driver for the SK Hynix Hi-846 8M pixel camera")
Signed-off-by: Wei Chen <harperchen1110@gmail.com>
---
Changes in v2:
 - move v4l2_ctrl_handler_free to error tag
 - handle memleak in other failure positions
Changes in v3:
 - add fixes commit tag

 drivers/media/i2c/hi846.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/hi846.c b/drivers/media/i2c/hi846.c
index 7c61873b7198..f86997a261f5 100644
--- a/drivers/media/i2c/hi846.c
+++ b/drivers/media/i2c/hi846.c
@@ -1472,21 +1472,26 @@ static int hi846_init_controls(struct hi846 *hi846)
 	if (ctrl_hdlr->error) {
 		dev_err(&client->dev, "v4l ctrl handler error: %d\n",
 			ctrl_hdlr->error);
-		return ctrl_hdlr->error;
+		ret = ctrl_hdlr->error;
+		goto error;
 	}
 
 	ret = v4l2_fwnode_device_parse(&client->dev, &props);
 	if (ret)
-		return ret;
+		goto error;
 
 	ret = v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, &hi846_ctrl_ops,
 					      &props);
 	if (ret)
-		return ret;
+		goto error;
 
 	hi846->sd.ctrl_handler = ctrl_hdlr;

 	return 0;
+
+error:
+	v4l2_ctrl_handler_free(ctrl_hdlr);
+	return ret;
 }
 
 static int hi846_set_video_mode(struct hi846 *hi846, int fps)
-- 
2.25.1


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

* Re: [PATCH v3] media: hi846: Fix memleak in hi846_init_controls()
  2023-03-27 11:58 [PATCH v3] media: hi846: Fix memleak in hi846_init_controls() Wei Chen
@ 2023-03-27 12:20 ` Martin Kepplinger
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Kepplinger @ 2023-03-27 12:20 UTC (permalink / raw)
  To: Wei Chen; +Cc: mchehab, linux-media, linux-kernel

Am Montag, dem 27.03.2023 um 11:58 +0000 schrieb Wei Chen:
> hi846_init_controls doesn't clean the allocated ctrl_hdlr
> in case there is a failure, which causes memleak. Add
> v4l2_ctrl_handler_free to free the resource properly.
> 
> Fixes: e8c0882685f9 ("media: i2c: add driver for the SK Hynix Hi-846
> 8M pixel camera")
> Signed-off-by: Wei Chen <harperchen1110@gmail.com>

just for the future: you don't need to send a new revision for tags-
addition only. That's usually something that maintainers can do when
applying, also (semi-)automated.

But *if* you send a new revision (due to other changes), you *should*
add all appropriate tags. So for this new revision you forgot this:

Reviewed-by: Martin Kepplinger <martin.kepplinger@puri.sm>

but, as you now know, you should not create a new revision for this
alone.

thanks,

                            martin



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

end of thread, other threads:[~2023-03-27 12:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-27 11:58 [PATCH v3] media: hi846: Fix memleak in hi846_init_controls() Wei Chen
2023-03-27 12:20 ` Martin Kepplinger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.