Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: Make of_clk_get_parent_name() robust with #clock-cells = 1

If a clock provider has #clock-cells = 1 and we call
of_clk_get_parent_name() on it we may end up returning the name
of the provider node if the provider doesn't have a
clock-output-names property. This doesn't make sense, especially
when you consider that calling of_clk_get_parent_name() on such a
node with different indices will return the same name each time.

Let's try getting the clock from the framework via of_clk_get()
instead, and only fallback to the node name if we have a provider
with #clock-cells = 0. This way, we can't hand out the same name
for different clocks when we don't actually know their names.

Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>

+20 -2
+20 -2
drivers/clk/clk.c
··· 3055 3055 u32 pv; 3056 3056 int rc; 3057 3057 int count; 3058 + struct clk *clk; 3058 3059 3059 3060 if (index < 0) 3060 3061 return NULL; ··· 3081 3080 3082 3081 if (of_property_read_string_index(clkspec.np, "clock-output-names", 3083 3082 index, 3084 - &clk_name) < 0) 3085 - clk_name = clkspec.np->name; 3083 + &clk_name) < 0) { 3084 + /* 3085 + * Best effort to get the name if the clock has been 3086 + * registered with the framework. If the clock isn't 3087 + * registered, we return the node name as the name of 3088 + * the clock as long as #clock-cells = 0. 3089 + */ 3090 + clk = of_clk_get_from_provider(&clkspec); 3091 + if (IS_ERR(clk)) { 3092 + if (clkspec.args_count == 0) 3093 + clk_name = clkspec.np->name; 3094 + else 3095 + clk_name = NULL; 3096 + } else { 3097 + clk_name = __clk_get_name(clk); 3098 + clk_put(clk); 3099 + } 3100 + } 3101 + 3086 3102 3087 3103 of_node_put(clkspec.np); 3088 3104 return clk_name;