of: call __of_parse_phandle_with_args from of_parse_phandle
authorStephen Warren <swarren@nvidia.com>
Wed, 14 Aug 2013 21:27:11 +0000 (15:27 -0600)
committerMark Brown <broonie@kernel.org>
Mon, 16 Feb 2015 02:35:05 +0000 (11:35 +0900)
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: Stephen Warren <swarren@nvidia.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Grant Likely <grant.likely@linaro.org>
(cherry picked from commit 91d9942c28ee691dab47185f38b052f84db4e0f7)
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/of/base.c

index ef2cce95669d9ca3c2e1e477f933e26b1a00c11e..a181a61b222dea9ef6704044241ba35830804824 100644 (file)
@@ -1112,13 +1112,20 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
                if (phandle) {
                        /*
                         * 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.
                         */
-                       node = of_find_node_by_phandle(phandle);
-                       if (!node) {
-                               pr_err("%s: could not find phandle\n",
-                                        np->full_name);
-                               goto err;
+                       if (cells_name || cur_index == index) {
+                               node = of_find_node_by_phandle(phandle);
+                               if (!node) {
+                                       pr_err("%s: could not find phandle\n",
+                                               np->full_name);
+                                       goto err;
+                               }
                        }
 
                        if (cells_name) {
@@ -1203,14 +1210,16 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
 struct device_node *of_parse_phandle(const struct device_node *np,
                                     const char *phandle_name, int index)
 {
-       const __be32 *phandle;
-       int size;
+       struct of_phandle_args args;
+
+       if (index < 0)
+               return NULL;
 
-       phandle = of_get_property(np, phandle_name, &size);
-       if ((!phandle) || (size < sizeof(*phandle) * (index + 1)))
+       if (__of_parse_phandle_with_args(np, phandle_name, NULL, 0,
+                                        index, &args))
                return NULL;
 
-       return of_find_node_by_phandle(be32_to_cpup(phandle + index));
+       return args.np;
 }
 EXPORT_SYMBOL(of_parse_phandle);