[PATCH] clk: imx: cpu: don't store the address of a function parameter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 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@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox




[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux