From 6413b090dedd8da4753453d25668098e5bc1f4e4 Mon Sep 17 00:00:00 2001 From: Valentine Barshak Date: Sat, 28 Dec 2013 16:09:08 +0400 Subject: [PATCH 1/2] clk: shmobile: Fix MSTP clock index Use clkidx when registering MSTP clocks instead of loop counter since the value is then used to access the specific clock index bit in the mstp register. The issue was introduced by the following commit: f94859c215b6d977 "clk: shmobile: Add MSTP clock support" Changes in V2: * none Signed-off-by: Valentine Barshak Acked-by: Laurent Pinchart Tested-by: Ben Dooks Signed-off-by: Mike Turquette --- drivers/clk/shmobile/clk-mstp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/clk/shmobile/clk-mstp.c b/drivers/clk/shmobile/clk-mstp.c index e576b60de20e..be7d0174cbfc 100644 --- a/drivers/clk/shmobile/clk-mstp.c +++ b/drivers/clk/shmobile/clk-mstp.c @@ -205,8 +205,8 @@ static void __init cpg_mstp_clocks_init(struct device_node *np) continue; } - clks[clkidx] = cpg_mstp_clock_register(name, parent_name, i, - group); + clks[clkidx] = cpg_mstp_clock_register(name, parent_name, + clkidx, group); if (!IS_ERR(clks[clkidx])) { group->data.clk_num = max(group->data.clk_num, clkidx); /* From 209f4fedcfdeeecfc9e87c045990230cc2162169 Mon Sep 17 00:00:00 2001 From: Valentine Barshak Date: Sat, 28 Dec 2013 16:09:09 +0400 Subject: [PATCH 2/2] clk: shmobile: Fix MSTP clock array initialization The clks member of the clk_onecell_data structure should point to a valid clk array (no NULL entries allowed), and the clk_num should be equal to the number of elements in the clks array. The MSTP driver fails to satisfy the above conditions. The clks array may contain NULL entries if not all clock-indices are initialized in the device tree. Thus, if the clock indices are interleaved we end up with NULL pointers in-between. The other problem is the driver uses maximum clock index as the number of clocks, which is incorrect (less than the actual number of clocks by 1). Fix the first issue by pre-setting the whole clks array with ERR_PTR(-ENOENT) pointers instead of zeros; and use maximum clkidx + 1 as the number of clocks to fix the other one. This should make of_clk_src_onecell_get() return the following: * valid clk pointers for all clocks registered; * ERR_PTR(-EINVAL) if (idx >= clk_data->clk_num); * ERR_PTR(-ENOENT) if the clock at the selected index was not initialized in the device tree (and was not registered). Changes in V2: * removed brackets from the one-line for loop Signed-off-by: Valentine Barshak Acked-by: Laurent Pinchart Tested-by: Ben Dooks Signed-off-by: Mike Turquette --- drivers/clk/shmobile/clk-mstp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/clk/shmobile/clk-mstp.c b/drivers/clk/shmobile/clk-mstp.c index be7d0174cbfc..42d5912b1d25 100644 --- a/drivers/clk/shmobile/clk-mstp.c +++ b/drivers/clk/shmobile/clk-mstp.c @@ -160,7 +160,7 @@ static void __init cpg_mstp_clocks_init(struct device_node *np) unsigned int i; group = kzalloc(sizeof(*group), GFP_KERNEL); - clks = kzalloc(MSTP_MAX_CLOCKS * sizeof(*clks), GFP_KERNEL); + clks = kmalloc(MSTP_MAX_CLOCKS * sizeof(*clks), GFP_KERNEL); if (group == NULL || clks == NULL) { kfree(group); kfree(clks); @@ -181,6 +181,9 @@ static void __init cpg_mstp_clocks_init(struct device_node *np) return; } + for (i = 0; i < MSTP_MAX_CLOCKS; ++i) + clks[i] = ERR_PTR(-ENOENT); + for (i = 0; i < MSTP_MAX_CLOCKS; ++i) { const char *parent_name; const char *name; @@ -208,7 +211,8 @@ static void __init cpg_mstp_clocks_init(struct device_node *np) clks[clkidx] = cpg_mstp_clock_register(name, parent_name, clkidx, group); if (!IS_ERR(clks[clkidx])) { - group->data.clk_num = max(group->data.clk_num, clkidx); + group->data.clk_num = max(group->data.clk_num, + clkidx + 1); /* * Register a clkdev to let board code retrieve the * clock by name and register aliases for non-DT