public inbox for linux-tegra@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: tegra: tegra124-emc: Fix potential memory leak
@ 2022-12-09  9:41 Yuan Can
  2023-02-10 23:23 ` Stephen Boyd
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Yuan Can @ 2022-12-09  9:41 UTC (permalink / raw)
  To: pdeschrijver, pgaikwad, mturquette, sboyd, thierry.reding,
	jonathanh, mperttunen, tomeu.vizoso, linux-clk, linux-tegra
  Cc: yuancan

The tegra and tegra needs to be freed in the error handling path, otherwise
it will be leaked.

Fixes: 2db04f16b589 ("clk: tegra: Add EMC clock driver")
Signed-off-by: Yuan Can <yuancan@huawei.com>
---
 drivers/clk/tegra/clk-tegra124-emc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/clk/tegra/clk-tegra124-emc.c b/drivers/clk/tegra/clk-tegra124-emc.c
index 219c80653dbd..2a6db0434281 100644
--- a/drivers/clk/tegra/clk-tegra124-emc.c
+++ b/drivers/clk/tegra/clk-tegra124-emc.c
@@ -464,6 +464,7 @@ static int load_timings_from_dt(struct tegra_clk_emc *tegra,
 		err = load_one_timing_from_dt(tegra, timing, child);
 		if (err) {
 			of_node_put(child);
+			kfree(tegra->timings);
 			return err;
 		}
 
@@ -515,6 +516,7 @@ struct clk *tegra124_clk_register_emc(void __iomem *base, struct device_node *np
 		err = load_timings_from_dt(tegra, node, node_ram_code);
 		if (err) {
 			of_node_put(node);
+			kfree(tegra);
 			return ERR_PTR(err);
 		}
 	}
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] clk: tegra: tegra124-emc: Fix potential memory leak
  2022-12-09  9:41 [PATCH] clk: tegra: tegra124-emc: Fix potential memory leak Yuan Can
@ 2023-02-10 23:23 ` Stephen Boyd
  2023-04-05 12:38 ` Thierry Reding
  2023-06-15  1:26 ` Stephen Boyd
  2 siblings, 0 replies; 4+ messages in thread
From: Stephen Boyd @ 2023-02-10 23:23 UTC (permalink / raw)
  To: Yuan Can, jonathanh, linux-clk, linux-tegra, mperttunen,
	mturquette, pdeschrijver, pgaikwad, thierry.reding, tomeu.vizoso
  Cc: yuancan

Quoting Yuan Can (2022-12-09 01:41:24)
> The tegra and tegra needs to be freed in the error handling path, otherwise
> it will be leaked.
> 
> Fixes: 2db04f16b589 ("clk: tegra: Add EMC clock driver")
> Signed-off-by: Yuan Can <yuancan@huawei.com>
> ---

Will anyone at Nvidia review this?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] clk: tegra: tegra124-emc: Fix potential memory leak
  2022-12-09  9:41 [PATCH] clk: tegra: tegra124-emc: Fix potential memory leak Yuan Can
  2023-02-10 23:23 ` Stephen Boyd
@ 2023-04-05 12:38 ` Thierry Reding
  2023-06-15  1:26 ` Stephen Boyd
  2 siblings, 0 replies; 4+ messages in thread
From: Thierry Reding @ 2023-04-05 12:38 UTC (permalink / raw)
  To: Yuan Can
  Cc: pdeschrijver, pgaikwad, mturquette, sboyd, jonathanh, mperttunen,
	tomeu.vizoso, linux-clk, linux-tegra

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

On Fri, Dec 09, 2022 at 09:41:24AM +0000, Yuan Can wrote:
> The tegra and tegra needs to be freed in the error handling path, otherwise
> it will be leaked.
> 
> Fixes: 2db04f16b589 ("clk: tegra: Add EMC clock driver")
> Signed-off-by: Yuan Can <yuancan@huawei.com>
> ---
>  drivers/clk/tegra/clk-tegra124-emc.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/clk/tegra/clk-tegra124-emc.c b/drivers/clk/tegra/clk-tegra124-emc.c
> index 219c80653dbd..2a6db0434281 100644
> --- a/drivers/clk/tegra/clk-tegra124-emc.c
> +++ b/drivers/clk/tegra/clk-tegra124-emc.c
> @@ -464,6 +464,7 @@ static int load_timings_from_dt(struct tegra_clk_emc *tegra,
>  		err = load_one_timing_from_dt(tegra, timing, child);
>  		if (err) {
>  			of_node_put(child);
> +			kfree(tegra->timings);
>  			return err;
>  		}
>  
> @@ -515,6 +516,7 @@ struct clk *tegra124_clk_register_emc(void __iomem *base, struct device_node *np
>  		err = load_timings_from_dt(tegra, node, node_ram_code);
>  		if (err) {
>  			of_node_put(node);
> +			kfree(tegra);
>  			return ERR_PTR(err);
>  		}
>  	}

Don't we need another kfree(tegra) in case the clk_register() fails? We
could do that as a follow-up and this patch isn't wrong, so:

Acked-by: Thierry Reding <treding@nvidia.com>

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] clk: tegra: tegra124-emc: Fix potential memory leak
  2022-12-09  9:41 [PATCH] clk: tegra: tegra124-emc: Fix potential memory leak Yuan Can
  2023-02-10 23:23 ` Stephen Boyd
  2023-04-05 12:38 ` Thierry Reding
@ 2023-06-15  1:26 ` Stephen Boyd
  2 siblings, 0 replies; 4+ messages in thread
From: Stephen Boyd @ 2023-06-15  1:26 UTC (permalink / raw)
  To: Yuan Can, jonathanh, linux-clk, linux-tegra, mperttunen,
	mturquette, pdeschrijver, pgaikwad, thierry.reding, tomeu.vizoso
  Cc: yuancan

Quoting Yuan Can (2022-12-09 01:41:24)
> The tegra and tegra needs to be freed in the error handling path, otherwise
> it will be leaked.
> 
> Fixes: 2db04f16b589 ("clk: tegra: Add EMC clock driver")
> Signed-off-by: Yuan Can <yuancan@huawei.com>
> ---

Applied to clk-next

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-06-15  1:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-09  9:41 [PATCH] clk: tegra: tegra124-emc: Fix potential memory leak Yuan Can
2023-02-10 23:23 ` Stephen Boyd
2023-04-05 12:38 ` Thierry Reding
2023-06-15  1:26 ` Stephen Boyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox