* [PATCH v4] media: rj54n1cb0c: Fix memleak in rj54n1_probe()
@ 2025-06-24 8:27 Zhang Shurong
2025-06-24 8:59 ` Jacopo Mondi
0 siblings, 1 reply; 2+ messages in thread
From: Zhang Shurong @ 2025-06-24 8:27 UTC (permalink / raw)
To: jacopo
Cc: mchehab, u.kleine-koenig, hverkuil, linux-media, linux-kernel,
Zhang Shurong
rj54n1_probe() won't clean all the allocated resources in fail
path, which may causes the memleaks. Add v4l2_ctrl_handler_free() to
prevent memleak.
Fixes: f187352dcd45 ("media: i2c: Copy rj54n1cb0c soc_camera sensor driver")
Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
---
Changes in v2:
- Fixed compile error
Changes in v3:
- Fixed coding style warnings identified by scripts/checkpatch.pl
Changes in v4:
- remove empty line between signed-off message and Fixes tag
- Moved ctrl_handler assignment after the error check
- Used existing error label for better code flow
---
drivers/media/i2c/rj54n1cb0c.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/media/i2c/rj54n1cb0c.c b/drivers/media/i2c/rj54n1cb0c.c
index b7ca39f63dba..6dfc91216851 100644
--- a/drivers/media/i2c/rj54n1cb0c.c
+++ b/drivers/media/i2c/rj54n1cb0c.c
@@ -1329,10 +1329,13 @@ static int rj54n1_probe(struct i2c_client *client)
V4L2_CID_GAIN, 0, 127, 1, 66);
v4l2_ctrl_new_std(&rj54n1->hdl, &rj54n1_ctrl_ops,
V4L2_CID_AUTO_WHITE_BALANCE, 0, 1, 1, 1);
- rj54n1->subdev.ctrl_handler = &rj54n1->hdl;
- if (rj54n1->hdl.error)
- return rj54n1->hdl.error;
+ if (rj54n1->hdl.error) {
+ ret = rj54n1->hdl.error;
+ goto err_free_ctrl;
+ }
+
+ rj54n1->subdev.ctrl_handler = &rj54n1->hdl;
rj54n1->clk_div = clk_div;
rj54n1->rect.left = RJ54N1_COLUMN_SKIP;
rj54n1->rect.top = RJ54N1_ROW_SKIP;
--
2.39.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v4] media: rj54n1cb0c: Fix memleak in rj54n1_probe()
2025-06-24 8:27 [PATCH v4] media: rj54n1cb0c: Fix memleak in rj54n1_probe() Zhang Shurong
@ 2025-06-24 8:59 ` Jacopo Mondi
0 siblings, 0 replies; 2+ messages in thread
From: Jacopo Mondi @ 2025-06-24 8:59 UTC (permalink / raw)
To: Zhang Shurong
Cc: jacopo, mchehab, u.kleine-koenig, hverkuil, linux-media,
linux-kernel
Hello Zhang
On Tue, Jun 24, 2025 at 04:27:24PM +0800, Zhang Shurong wrote:
> rj54n1_probe() won't clean all the allocated resources in fail
> path, which may causes the memleaks. Add v4l2_ctrl_handler_free() to
> prevent memleak.
>
> Fixes: f187352dcd45 ("media: i2c: Copy rj54n1cb0c soc_camera sensor driver")
> Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
Thanks for addressing my comments on the previous version
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Thanks
j
> ---
> Changes in v2:
> - Fixed compile error
> Changes in v3:
> - Fixed coding style warnings identified by scripts/checkpatch.pl
> Changes in v4:
> - remove empty line between signed-off message and Fixes tag
> - Moved ctrl_handler assignment after the error check
> - Used existing error label for better code flow
> ---
> drivers/media/i2c/rj54n1cb0c.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/media/i2c/rj54n1cb0c.c b/drivers/media/i2c/rj54n1cb0c.c
> index b7ca39f63dba..6dfc91216851 100644
> --- a/drivers/media/i2c/rj54n1cb0c.c
> +++ b/drivers/media/i2c/rj54n1cb0c.c
> @@ -1329,10 +1329,13 @@ static int rj54n1_probe(struct i2c_client *client)
> V4L2_CID_GAIN, 0, 127, 1, 66);
> v4l2_ctrl_new_std(&rj54n1->hdl, &rj54n1_ctrl_ops,
> V4L2_CID_AUTO_WHITE_BALANCE, 0, 1, 1, 1);
> - rj54n1->subdev.ctrl_handler = &rj54n1->hdl;
> - if (rj54n1->hdl.error)
> - return rj54n1->hdl.error;
>
> + if (rj54n1->hdl.error) {
> + ret = rj54n1->hdl.error;
> + goto err_free_ctrl;
> + }
> +
> + rj54n1->subdev.ctrl_handler = &rj54n1->hdl;
> rj54n1->clk_div = clk_div;
> rj54n1->rect.left = RJ54N1_COLUMN_SKIP;
> rj54n1->rect.top = RJ54N1_ROW_SKIP;
> --
> 2.39.5
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-06-24 8:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-24 8:27 [PATCH v4] media: rj54n1cb0c: Fix memleak in rj54n1_probe() Zhang Shurong
2025-06-24 8:59 ` Jacopo Mondi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).