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>
This commit is contained in:
parent
087a920d4a
commit
0a4807c2f9
|
@ -3055,6 +3055,7 @@ const char *of_clk_get_parent_name(struct device_node *np, int index)
|
||||||
u32 pv;
|
u32 pv;
|
||||||
int rc;
|
int rc;
|
||||||
int count;
|
int count;
|
||||||
|
struct clk *clk;
|
||||||
|
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -3080,8 +3081,25 @@ const char *of_clk_get_parent_name(struct device_node *np, int index)
|
||||||
|
|
||||||
if (of_property_read_string_index(clkspec.np, "clock-output-names",
|
if (of_property_read_string_index(clkspec.np, "clock-output-names",
|
||||||
index,
|
index,
|
||||||
&clk_name) < 0)
|
&clk_name) < 0) {
|
||||||
|
/*
|
||||||
|
* Best effort to get the name if the clock has been
|
||||||
|
* registered with the framework. If the clock isn't
|
||||||
|
* registered, we return the node name as the name of
|
||||||
|
* the clock as long as #clock-cells = 0.
|
||||||
|
*/
|
||||||
|
clk = of_clk_get_from_provider(&clkspec);
|
||||||
|
if (IS_ERR(clk)) {
|
||||||
|
if (clkspec.args_count == 0)
|
||||||
clk_name = clkspec.np->name;
|
clk_name = clkspec.np->name;
|
||||||
|
else
|
||||||
|
clk_name = NULL;
|
||||||
|
} else {
|
||||||
|
clk_name = __clk_get_name(clk);
|
||||||
|
clk_put(clk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
of_node_put(clkspec.np);
|
of_node_put(clkspec.np);
|
||||||
return clk_name;
|
return clk_name;
|
||||||
|
|
Loading…
Reference in New Issue