mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tommaso Merciai <tommaso.merciai@amarulasolutions.com>
To: Rafael Mendonca <rafaelmendsr@gmail.com>
Cc: Martin Kepplinger <martink@posteo.de>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Pavel Machek <pavel@ucw.cz>,
	Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] media: i2c: hi846: Fix memory leak in hi846_parse_dt()
Date: Mon, 19 Sep 2022 16:47:40 +0200	[thread overview]
Message-ID: <20220919144740.GD3958@tom-ThinkPad-T14s-Gen-2i> (raw)
In-Reply-To: <20220919021252.730729-1-rafaelmendsr@gmail.com>

Hi Rafael,

On Sun, Sep 18, 2022 at 11:12:51PM -0300, Rafael Mendonca wrote:
> If any of the checks related to the supported link frequencies fail, then
> the V4L2 fwnode resources don't get released before returning, which leads
> to a memleak. Fix this by properly freeing the V4L2 fwnode data in a
> designated label.
> 
> Fixes: e8c0882685f9 ("media: i2c: add driver for the SK Hynix Hi-846 8M pixel camera")
> Signed-off-by: Rafael Mendonca <rafaelmendsr@gmail.com>
> ---
>  drivers/media/i2c/hi846.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/i2c/hi846.c b/drivers/media/i2c/hi846.c
> index ad35c3ff3611..254031503c72 100644
> --- a/drivers/media/i2c/hi846.c
> +++ b/drivers/media/i2c/hi846.c
> @@ -2008,22 +2008,24 @@ static int hi846_parse_dt(struct hi846 *hi846, struct device *dev)
>  	    bus_cfg.bus.mipi_csi2.num_data_lanes != 4) {
>  		dev_err(dev, "number of CSI2 data lanes %d is not supported",
>  			bus_cfg.bus.mipi_csi2.num_data_lanes);
> -		v4l2_fwnode_endpoint_free(&bus_cfg);
> -		return -EINVAL;
> +		ret = -EINVAL;
> +		goto check_hwcfg_error;
>  	}
>  
>  	hi846->nr_lanes = bus_cfg.bus.mipi_csi2.num_data_lanes;
>  
>  	if (!bus_cfg.nr_of_link_frequencies) {
>  		dev_err(dev, "link-frequency property not found in DT\n");
> -		return -EINVAL;
> +		ret = -EINVAL;
> +		goto check_hwcfg_error;
>  	}
>  
>  	/* Check that link frequences for all the modes are in device tree */
>  	fq = hi846_check_link_freqs(hi846, &bus_cfg);
>  	if (fq) {
>  		dev_err(dev, "Link frequency of %lld is not supported\n", fq);
> -		return -EINVAL;
> +		ret = -EINVAL;
> +		goto check_hwcfg_error;
>  	}
>  
>  	v4l2_fwnode_endpoint_free(&bus_cfg);
> @@ -2044,6 +2046,10 @@ static int hi846_parse_dt(struct hi846 *hi846, struct device *dev)
>  	}
>  
>  	return 0;
> +
> +check_hwcfg_error:
> +	v4l2_fwnode_endpoint_free(&bus_cfg);
> +	return ret;
>  }
>  
>  static int hi846_probe(struct i2c_client *client)
> -- 
> 2.34.1
> 

Looks good to me.

Reviewed-by: Tommaso Merciai <tommaso.merciai@amarulasolutions.com>


Regards,
Tommaso

-- 
Tommaso Merciai
Embedded Linux Engineer
tommaso.merciai@amarulasolutions.com
__________________________________

Amarula Solutions SRL
Via Le Canevare 30, 31100 Treviso, Veneto, IT
T. +39 042 243 5310
info@amarulasolutions.com
www.amarulasolutions.com

  reply	other threads:[~2022-09-19 14:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-19  2:12 Rafael Mendonca
2022-09-19 14:47 ` Tommaso Merciai [this message]
2022-09-20  9:28 ` Martin Kepplinger

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=20220919144740.GD3958@tom-ThinkPad-T14s-Gen-2i \
    --to=tommaso.merciai@amarulasolutions.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=martink@posteo.de \
    --cc=mchehab+huawei@kernel.org \
    --cc=mchehab@kernel.org \
    --cc=pavel@ucw.cz \
    --cc=rafaelmendsr@gmail.com \
    --cc=sakari.ailus@linux.intel.com \
    /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®