aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/of/base.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 1f80acf4c16a..7c75d7551eb9 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1111,13 +1111,20 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
1111 if (phandle) { 1111 if (phandle) {
1112 /* 1112 /*
1113 * Find the provider node and parse the #*-cells 1113 * Find the provider node and parse the #*-cells
1114 * property to determine the argument length 1114 * property to determine the argument length.
1115 *
1116 * This is not needed if the cell count is hard-coded
1117 * (i.e. cells_name not set, but cell_count is set),
1118 * except when we're going to return the found node
1119 * below.
1115 */ 1120 */
1116 node = of_find_node_by_phandle(phandle); 1121 if (cells_name || cur_index == index) {
1117 if (!node) { 1122 node = of_find_node_by_phandle(phandle);
1118 pr_err("%s: could not find phandle\n", 1123 if (!node) {
1119 np->full_name); 1124 pr_err("%s: could not find phandle\n",
1120 goto err; 1125 np->full_name);
1126 goto err;
1127 }
1121 } 1128 }
1122 1129
1123 if (cells_name) { 1130 if (cells_name) {
@@ -1202,14 +1209,16 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
1202struct device_node *of_parse_phandle(const struct device_node *np, 1209struct device_node *of_parse_phandle(const struct device_node *np,
1203 const char *phandle_name, int index) 1210 const char *phandle_name, int index)
1204{ 1211{
1205 const __be32 *phandle; 1212 struct of_phandle_args args;
1206 int size; 1213
1214 if (index < 0)
1215 return NULL;
1207 1216
1208 phandle = of_get_property(np, phandle_name, &size); 1217 if (__of_parse_phandle_with_args(np, phandle_name, NULL, 0,
1209 if ((!phandle) || (size < sizeof(*phandle) * (index + 1))) 1218 index, &args))
1210 return NULL; 1219 return NULL;
1211 1220
1212 return of_find_node_by_phandle(be32_to_cpup(phandle + index)); 1221 return args.np;
1213} 1222}
1214EXPORT_SYMBOL(of_parse_phandle); 1223EXPORT_SYMBOL(of_parse_phandle);
1215 1224