mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Martin Kepplinger <martink@posteo.de>
To: Wei Chen <harperchen1110@gmail.com>
Cc: mchehab@kernel.org, linux-media@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] media: hi846: Fix memleak in hi846_init_controls()
Date: Mon, 27 Mar 2023 06:17:51 +0000	[thread overview]
Message-ID: <275cf656630a4e247daf4d52e1feb5ba0ada898b.camel@posteo.de> (raw)
In-Reply-To: <20230326092712.139791-1-harperchen1110@gmail.com>

Am Sonntag, dem 26.03.2023 um 09:27 +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.
> 
> Signed-off-by: Wei Chen <harperchen1110@gmail.com>

you could also add

Fixes: e8c0882685f9 ("media: i2c: add driver for the SK Hynix Hi-846 8M
pixel camera")

> ---
> 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(-)
> 
> 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)



      parent reply	other threads:[~2023-03-27  6:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-26  9:27 Wei Chen
2023-03-26 10:22 ` Martin Kepplinger
2023-03-27  6:17 ` Martin Kepplinger [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=275cf656630a4e247daf4d52e1feb5ba0ada898b.camel@posteo.de \
    --to=martink@posteo.de \
    --cc=harperchen1110@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®