public inbox for linux-clk@vger.kernel.org
 help / color / mirror / Atom feed
From: "Jonathan Neuschäfer" <j.neuschaefer@gmx.net>
To: Tao Lan <taolan@huawei.com>
Cc: mturquette@baylibre.com, sboyd@kernel.org, j.neuschaefer@gmx.net,
	linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] clk: fix memory leak in hisi_clk_init.
Date: Sun, 13 Aug 2023 23:58:55 +0200	[thread overview]
Message-ID: <ZNlSH+eWV8Sk3FYn@probook> (raw)
In-Reply-To: <20221222091221.28308-1-taolan@huawei.com>

[-- Attachment #1: Type: text/plain, Size: 1247 bytes --]

Hello,

sorry for the delay, but I found this unmerged patch while cleaning up
my mailbox.

On Thu, Dec 22, 2022 at 09:12:21AM +0000, Tao Lan wrote:
> From: taolan <taolan@huawei.com>
> 
> when clk_data create fail, we also need to release base.
> 
> Signed-off-by: taolan <taolan@huawei.com>
> ---
>  drivers/clk/hisilicon/clk.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/clk/hisilicon/clk.c b/drivers/clk/hisilicon/clk.c
> index 54d9fdc93599..9ca4fc05fa57 100644
> --- a/drivers/clk/hisilicon/clk.c
> +++ b/drivers/clk/hisilicon/clk.c
> @@ -82,6 +82,10 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np,
>  	of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data->clk_data);
>  	return clk_data;
>  err_data:
> +	if (base) {
> +		iounmap(base);
> +		base = NULL;
> +	}

This is inaccurate. Consider the case when kzalloc fails:

	clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
	if (!clk_data)
		goto err;

base has already been mapped, but the code jumps to 'err', which doesn't
have the iounmap.

To address this properly, you'd have to add another label between
err_data and err.


>  	kfree(clk_data);
>  err:
>  	return NULL;


Best regards,
jn

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2023-08-13 22:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-22  9:12 [PATCH] clk: fix memory leak in hisi_clk_init Tao Lan
2023-08-13 21:58 ` Jonathan Neuschäfer [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=ZNlSH+eWV8Sk3FYn@probook \
    --to=j.neuschaefer@gmx.net \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@kernel.org \
    --cc=taolan@huawei.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