of: resolver: Simplify of_resolve_phandles() using __free()
[ Upstream commit 5275e8b5293f65cc82a5ee5eab02dd573b911d6e ] Use the __free() cleanup to simplify of_resolve_phandles() and remove all the goto's. Signed-off-by: Rob Herring (Arm) <robh@kernel.org> Stable-dep-of: a46a0805635d ("of: resolver: Fix device node refcount leakage in of_resolve_phandles()") Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
56ddf0023b
commit
05576e1304
+11
-23
@@ -250,24 +250,20 @@ static int adjust_local_phandle_references(struct device_node *local_fixups,
|
|||||||
int of_resolve_phandles(struct device_node *overlay)
|
int of_resolve_phandles(struct device_node *overlay)
|
||||||
{
|
{
|
||||||
struct device_node *child, *local_fixups, *refnode;
|
struct device_node *child, *local_fixups, *refnode;
|
||||||
struct device_node *tree_symbols, *overlay_fixups;
|
struct device_node *overlay_fixups;
|
||||||
struct property *prop;
|
struct property *prop;
|
||||||
const char *refpath;
|
const char *refpath;
|
||||||
phandle phandle, phandle_delta;
|
phandle phandle, phandle_delta;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
tree_symbols = NULL;
|
|
||||||
|
|
||||||
if (!overlay) {
|
if (!overlay) {
|
||||||
pr_err("null overlay\n");
|
pr_err("null overlay\n");
|
||||||
err = -EINVAL;
|
return -EINVAL;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!of_node_check_flag(overlay, OF_DETACHED)) {
|
if (!of_node_check_flag(overlay, OF_DETACHED)) {
|
||||||
pr_err("overlay not detached\n");
|
pr_err("overlay not detached\n");
|
||||||
err = -EINVAL;
|
return -EINVAL;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
phandle_delta = live_tree_max_phandle() + 1;
|
phandle_delta = live_tree_max_phandle() + 1;
|
||||||
@@ -279,7 +275,7 @@ int of_resolve_phandles(struct device_node *overlay)
|
|||||||
|
|
||||||
err = adjust_local_phandle_references(local_fixups, overlay, phandle_delta);
|
err = adjust_local_phandle_references(local_fixups, overlay, phandle_delta);
|
||||||
if (err)
|
if (err)
|
||||||
goto out;
|
return err;
|
||||||
|
|
||||||
overlay_fixups = NULL;
|
overlay_fixups = NULL;
|
||||||
|
|
||||||
@@ -288,16 +284,13 @@ int of_resolve_phandles(struct device_node *overlay)
|
|||||||
overlay_fixups = child;
|
overlay_fixups = child;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!overlay_fixups) {
|
if (!overlay_fixups)
|
||||||
err = 0;
|
return 0;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
tree_symbols = of_find_node_by_path("/__symbols__");
|
struct device_node __free(device_node) *tree_symbols = of_find_node_by_path("/__symbols__");
|
||||||
if (!tree_symbols) {
|
if (!tree_symbols) {
|
||||||
pr_err("no symbols in root of device tree.\n");
|
pr_err("no symbols in root of device tree.\n");
|
||||||
err = -EINVAL;
|
return -EINVAL;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for_each_property_of_node(overlay_fixups, prop) {
|
for_each_property_of_node(overlay_fixups, prop) {
|
||||||
@@ -311,14 +304,12 @@ int of_resolve_phandles(struct device_node *overlay)
|
|||||||
if (err) {
|
if (err) {
|
||||||
pr_err("node label '%s' not found in live devicetree symbols table\n",
|
pr_err("node label '%s' not found in live devicetree symbols table\n",
|
||||||
prop->name);
|
prop->name);
|
||||||
goto out;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
refnode = of_find_node_by_path(refpath);
|
refnode = of_find_node_by_path(refpath);
|
||||||
if (!refnode) {
|
if (!refnode)
|
||||||
err = -ENOENT;
|
return -ENOENT;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
phandle = refnode->phandle;
|
phandle = refnode->phandle;
|
||||||
of_node_put(refnode);
|
of_node_put(refnode);
|
||||||
@@ -328,11 +319,8 @@ int of_resolve_phandles(struct device_node *overlay)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
|
||||||
if (err)
|
if (err)
|
||||||
pr_err("overlay phandle fixup failed: %d\n", err);
|
pr_err("overlay phandle fixup failed: %d\n", err);
|
||||||
of_node_put(tree_symbols);
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(of_resolve_phandles);
|
EXPORT_SYMBOL_GPL(of_resolve_phandles);
|
||||||
|
|||||||
Reference in New Issue
Block a user