Commit 23ce04c0 authored by Grant Likely's avatar Grant Likely

of/base: Clean up exit paths for of_parse_phandle_with_args()

Some of the exit paths were not correctly releasing the node. Fix it by
creating an 'err' label for collecting the error paths and releasing the
node.

Cc: Rob Herring <rob.herring@calxeda.com>
Signed-off-by: default avatarGrant Likely <grant.likely@secretlab.ca>
parent cabb7d5b
...@@ -1096,7 +1096,7 @@ int of_parse_phandle_with_args(const struct device_node *np, const char *list_na ...@@ -1096,7 +1096,7 @@ int of_parse_phandle_with_args(const struct device_node *np, const char *list_na
struct of_phandle_args *out_args) struct of_phandle_args *out_args)
{ {
const __be32 *list, *list_end; const __be32 *list, *list_end;
int size, cur_index = 0; int rc = 0, size, cur_index = 0;
uint32_t count = 0; uint32_t count = 0;
struct device_node *node = NULL; struct device_node *node = NULL;
phandle phandle; phandle phandle;
...@@ -1109,6 +1109,7 @@ int of_parse_phandle_with_args(const struct device_node *np, const char *list_na ...@@ -1109,6 +1109,7 @@ int of_parse_phandle_with_args(const struct device_node *np, const char *list_na
/* Loop over the phandles until all the requested entry is found */ /* Loop over the phandles until all the requested entry is found */
while (list < list_end) { while (list < list_end) {
rc = -EINVAL;
count = 0; count = 0;
/* /*
...@@ -1125,13 +1126,13 @@ int of_parse_phandle_with_args(const struct device_node *np, const char *list_na ...@@ -1125,13 +1126,13 @@ int of_parse_phandle_with_args(const struct device_node *np, const char *list_na
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);
break; goto err;
} }
if (of_property_read_u32(node, cells_name, &count)) { if (of_property_read_u32(node, cells_name, &count)) {
pr_err("%s: could not get %s for %s\n", pr_err("%s: could not get %s for %s\n",
np->full_name, cells_name, np->full_name, cells_name,
node->full_name); node->full_name);
break; goto err;
} }
/* /*
...@@ -1141,7 +1142,7 @@ int of_parse_phandle_with_args(const struct device_node *np, const char *list_na ...@@ -1141,7 +1142,7 @@ int of_parse_phandle_with_args(const struct device_node *np, const char *list_na
if (list + count > list_end) { if (list + count > list_end) {
pr_err("%s: arguments longer than property\n", pr_err("%s: arguments longer than property\n",
np->full_name); np->full_name);
break; goto err;
} }
} }
...@@ -1151,9 +1152,10 @@ int of_parse_phandle_with_args(const struct device_node *np, const char *list_na ...@@ -1151,9 +1152,10 @@ int of_parse_phandle_with_args(const struct device_node *np, const char *list_na
* index matches, then fill the out_args structure and return, * index matches, then fill the out_args structure and return,
* or return -ENOENT for an empty entry. * or return -ENOENT for an empty entry.
*/ */
rc = -ENOENT;
if (cur_index == index) { if (cur_index == index) {
if (!phandle) if (!phandle)
return -ENOENT; goto err;
if (out_args) { if (out_args) {
int i; int i;
...@@ -1164,6 +1166,10 @@ int of_parse_phandle_with_args(const struct device_node *np, const char *list_na ...@@ -1164,6 +1166,10 @@ int of_parse_phandle_with_args(const struct device_node *np, const char *list_na
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
out_args->args[i] = be32_to_cpup(list++); out_args->args[i] = be32_to_cpup(list++);
} }
/* Found it! return success */
if (node)
of_node_put(node);
return 0; return 0;
} }
...@@ -1173,10 +1179,16 @@ int of_parse_phandle_with_args(const struct device_node *np, const char *list_na ...@@ -1173,10 +1179,16 @@ int of_parse_phandle_with_args(const struct device_node *np, const char *list_na
cur_index++; cur_index++;
} }
/* Loop exited without finding a valid entry; return an error */ /*
* Unlock node before returning result; will be one of:
* -ENOENT : index is for empty phandle
* -EINVAL : parsing error on data
*/
rc = -ENOENT;
err:
if (node) if (node)
of_node_put(node); of_node_put(node);
return -EINVAL; return rc;
} }
EXPORT_SYMBOL(of_parse_phandle_with_args); EXPORT_SYMBOL(of_parse_phandle_with_args);
......
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