Commit 91d9942c authored by Stephen Warren's avatar Stephen Warren Committed by Grant Likely

of: call __of_parse_phandle_with_args from of_parse_phandle

The simplest case of __of_parse_phandle_with_args() now implements the
semantics of of_parse_phandle(). Rewrite of_parse_phandle() to call
__of_parse_phandle_with_args() rather than open-coding the simple case.

Optimize __of_parse_phandle_with_args() so that it doesn't call
of_find_node_by_phandle() except when it's strictly needed. This avoids
introducing too much overhead when replacing of_parse_phandle().
Signed-off-by: default avatarStephen Warren <swarren@nvidia.com>
Acked-by: default avatarMark Rutland <mark.rutland@arm.com>
Signed-off-by: default avatarGrant Likely <grant.likely@linaro.org>
parent 035fd948
...@@ -1111,14 +1111,21 @@ static int __of_parse_phandle_with_args(const struct device_node *np, ...@@ -1111,14 +1111,21 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
if (phandle) { if (phandle) {
/* /*
* Find the provider node and parse the #*-cells * Find the provider node and parse the #*-cells
* property to determine the argument length * property to determine the argument length.
*
* This is not needed if the cell count is hard-coded
* (i.e. cells_name not set, but cell_count is set),
* except when we're going to return the found node
* below.
*/ */
if (cells_name || cur_index == index) {
node = of_find_node_by_phandle(phandle); node = of_find_node_by_phandle(phandle);
if (!node) { if (!node) {
pr_err("%s: could not find phandle\n", pr_err("%s: could not find phandle\n",
np->full_name); np->full_name);
goto err; goto err;
} }
}
if (cells_name) { if (cells_name) {
if (of_property_read_u32(node, cells_name, if (of_property_read_u32(node, cells_name,
...@@ -1202,14 +1209,16 @@ static int __of_parse_phandle_with_args(const struct device_node *np, ...@@ -1202,14 +1209,16 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
struct device_node *of_parse_phandle(const struct device_node *np, struct device_node *of_parse_phandle(const struct device_node *np,
const char *phandle_name, int index) const char *phandle_name, int index)
{ {
const __be32 *phandle; struct of_phandle_args args;
int size;
if (index < 0)
return NULL;
phandle = of_get_property(np, phandle_name, &size); if (__of_parse_phandle_with_args(np, phandle_name, NULL, 0,
if ((!phandle) || (size < sizeof(*phandle) * (index + 1))) index, &args))
return NULL; return NULL;
return of_find_node_by_phandle(be32_to_cpup(phandle + index)); return args.np;
} }
EXPORT_SYMBOL(of_parse_phandle); EXPORT_SYMBOL(of_parse_phandle);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment