Skip to contentSkip to conversation

clk: tegra: tegra124-emc: Fix potential memory leak

PATCH Applied Yuan Can 3 participants 4 messages Dec 9, 2022 – Jun 15, 2023

Subsystems (3)
lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH 1/1 clk: tegra: tegra124-emc: Fix potential memory leak

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")
---
 drivers/clk/tegra/clk-tegra124-emc.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clk/tegra/clk-tegra124-emc.c +2 -0
index 219c80653dbd..2a6db0434281 100644
@@ -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);
 		}
 	}
Signature · 1 line
2.17.1
maintainer
#1 lore raw

Quoting Yuan Can (2022-12-09 01:41:24)

Quoted 6 lines

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

---

Will anyone at Nvidia review this?

Acked-by on v1 1/1
#2 lore raw
In reply to Yuan Can
Quoted 22 lines · Yuan Can

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")
---
 drivers/clk/tegra/clk-tegra124-emc.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clk/tegra/clk-tegra124-emc.c +1 -0
index 219c80653dbd..2a6db0434281 100644
@@ -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;
 		}
 

drivers/clk/tegra/clk-tegra124-emc.c struct clk *tegra124_clk_register_emc(void __iomem *base, struct device_node *np · line 522

Quoted 7 lines
drivers/clk/tegra/clk-tegra124-emc.c +1 -0
@@ -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:

maintainer Applied
#3 lore raw
In reply to Yuan Can

Quoting Yuan Can (2022-12-09 01:41:24)

Quoted 6 lines

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

---

Applied to clk-next