media: hi846: Fix memleak in hi846_init_controls()
PATCH v2 1/1 media: hi846: Fix memleak in hi846_init_controls()
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.
---
Changes in v2:
- move v4l2_ctrl_handler_free to error tag
- handle memleak in other failure positions
drivers/media/i2c/hi846.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/media/i2c/hi846.c +8 -3
@@ -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)
Signature · 1 line
2.25.1
Am Sonntag, dem 26.03.2023 um 09:27 +0000 schrieb Wei Chen:
Quoted 5 lines
hi846_init_controlsdoesn't clean the allocatedctrl_hdlrin case there is a failure, which causes memleak. Addv4l2_ctrl_handler_freeto free the resource properly.Signed-off-by Wei Chen <[email protected]>
thanks,
martin
Quoted 44 lines
---
Changes in v2:
- movev4l2_ctrl_handler_freeto error tag
- handle memleak in other failure positionsdrivers/media/i2c/hi846.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)drivers/media/i2c/hi846.c +2
-1@@ -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;
drivers/media/i2c/hi846.c +4
-0+ +error: + v4l2_ctrl_handler_free(ctrl_hdlr); + return ret;}
static inthi846_set_video_mode(struct hi846 *hi846, int fps)
Martin Kepplinger
maintainerAm Sonntag, dem 26.03.2023 um 09:27 +0000 schrieb Wei Chen:
Quoted 5 lines
hi846_init_controlsdoesn't clean the allocatedctrl_hdlrin case there is a failure, which causes memleak. Addv4l2_ctrl_handler_freeto free the resource properly.Signed-off-by Wei Chen <[email protected]>
you could also add
pixel camera")
Quoted 44 lines
---
Changes in v2:
- movev4l2_ctrl_handler_freeto error tag
- handle memleak in other failure positionsdrivers/media/i2c/hi846.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)drivers/media/i2c/hi846.c +2
-1@@ -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;
drivers/media/i2c/hi846.c +4
-0+ +error: + v4l2_ctrl_handler_free(ctrl_hdlr); + return ret;}
static inthi846_set_video_mode(struct hi846 *hi846, int fps)