mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] clk: imx: cpu: don't store the address of a function parameter
@ 2017-08-03 19:14 Uwe Kleine-König
  0 siblings, 0 replies; only message in thread
From: Uwe Kleine-König @ 2017-08-03 19:14 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

The function imx_clk_cpu takes a const char *parent_name as second
paramter. The implementation introduced in commit 9a89ed9d281e then
uses the address of this function parameter to assign clk.parent_names.
This is an address on the stack that is saved in the clk tree and of
course this is easily overwritten by later execution paths of barebox.

Without this fix the clk_dump command reproducibly crashes on i.MX7
(which is the only SoC that makes use of imx_clk_cpu()).

Fixes: 9a89ed9d281e ("clk: imx: Add clk-cpu support")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/clk/imx/clk-cpu.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/imx/clk-cpu.c b/drivers/clk/imx/clk-cpu.c
index bd1749fd870b..5ac0ed178932 100644
--- a/drivers/clk/imx/clk-cpu.c
+++ b/drivers/clk/imx/clk-cpu.c
@@ -82,14 +82,22 @@ static const struct clk_ops clk_cpu_ops = {
 	.set_rate	= clk_cpu_set_rate,
 };
 
+struct imx_clk_cpu {
+	struct clk_cpu cpu;
+	const char *parent_name;
+};
+
 struct clk *imx_clk_cpu(const char *name, const char *parent_name,
 		struct clk *div, struct clk *mux, struct clk *pll,
 		struct clk *step)
 {
+	struct imx_clk_cpu *icpu;
 	struct clk_cpu *cpu;
 	int ret;
 
-	cpu = xzalloc(sizeof(*cpu));
+	icpu = xzalloc(sizeof(*icpu));
+	icpu->parent_name = parent_name;
+	cpu = &icpu->cpu;
 
 	cpu->div = div;
 	cpu->mux = mux;
@@ -99,7 +107,7 @@ struct clk *imx_clk_cpu(const char *name, const char *parent_name,
 	cpu->clk.name = name;
 	cpu->clk.ops = &clk_cpu_ops;
 	cpu->clk.flags = 0;
-	cpu->clk.parent_names = &parent_name;
+	cpu->clk.parent_names = &icpu->parent_name;
 	cpu->clk.num_parents = 1;
 
 	ret = clk_register(&cpu->clk);
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-08-03 19:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-03 19:14 [PATCH] clk: imx: cpu: don't store the address of a function parameter Uwe Kleine-König

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