Commit 25e16877 authored by Frank Rowand's avatar Frank Rowand Committed by Rob Herring

of: Rename variables to better reflect purpose or follow convention

Rename variables to better reflect what their purpose is.  As a side
effect, this reduces the need for some of the comments previously
removed in this series.
Signed-off-by: default avatarFrank Rowand <frank.rowand@am.sony.com>
Signed-off-by: default avatarRob Herring <robh@kernel.org>
parent fad556bf
...@@ -74,17 +74,17 @@ static phandle live_tree_max_phandle(void) ...@@ -74,17 +74,17 @@ static phandle live_tree_max_phandle(void)
/* /*
* Adjust a subtree's phandle values by a given delta. * Adjust a subtree's phandle values by a given delta.
*/ */
static void adjust_overlay_phandles(struct device_node *node, static void adjust_overlay_phandles(struct device_node *overlay,
int phandle_delta) int phandle_delta)
{ {
struct device_node *child; struct device_node *child;
struct property *prop; struct property *prop;
phandle phandle; phandle phandle;
if (node->phandle != 0 && node->phandle != OF_PHANDLE_ILLEGAL) if (overlay->phandle != 0 && overlay->phandle != OF_PHANDLE_ILLEGAL)
node->phandle += phandle_delta; overlay->phandle += phandle_delta;
for_each_property_of_node(node, prop) { for_each_property_of_node(overlay, prop) {
if (of_prop_cmp(prop->name, "phandle") && if (of_prop_cmp(prop->name, "phandle") &&
of_prop_cmp(prop->name, "linux,phandle")) of_prop_cmp(prop->name, "linux,phandle"))
...@@ -97,41 +97,40 @@ static void adjust_overlay_phandles(struct device_node *node, ...@@ -97,41 +97,40 @@ static void adjust_overlay_phandles(struct device_node *node,
if (phandle == OF_PHANDLE_ILLEGAL) if (phandle == OF_PHANDLE_ILLEGAL)
continue; continue;
*(uint32_t *)prop->value = cpu_to_be32(node->phandle); *(uint32_t *)prop->value = cpu_to_be32(overlay->phandle);
} }
for_each_child_of_node(node, child) for_each_child_of_node(overlay, child)
adjust_overlay_phandles(child, phandle_delta); adjust_overlay_phandles(child, phandle_delta);
} }
static int update_usages_of_a_phandle_reference(struct device_node *node, static int update_usages_of_a_phandle_reference(struct device_node *overlay,
struct property *rprop, int value) struct property *prop_fixup, phandle phandle)
{ {
phandle phandle;
struct device_node *refnode; struct device_node *refnode;
struct property *sprop; struct property *prop;
char *propval, *propcur, *propend, *nodestr, *propstr, *s; char *value, *cur, *end, *node_path, *prop_name, *s;
int offset, propcurlen; int offset, len;
int err = 0; int err = 0;
propval = kmalloc(rprop->length, GFP_KERNEL); value = kmalloc(prop_fixup->length, GFP_KERNEL);
if (!propval) if (!value)
return -ENOMEM; return -ENOMEM;
memcpy(propval, rprop->value, rprop->length); memcpy(value, prop_fixup->value, prop_fixup->length);
propend = propval + rprop->length; end = value + prop_fixup->length;
for (propcur = propval; propcur < propend; propcur += propcurlen + 1) { for (cur = value; cur < end; cur += len + 1) {
propcurlen = strlen(propcur); len = strlen(cur);
nodestr = propcur; node_path = cur;
s = strchr(propcur, ':'); s = strchr(cur, ':');
if (!s) { if (!s) {
err = -EINVAL; err = -EINVAL;
goto err_fail; goto err_fail;
} }
*s++ = '\0'; *s++ = '\0';
propstr = s; prop_name = s;
s = strchr(s, ':'); s = strchr(s, ':');
if (!s) { if (!s) {
err = -EINVAL; err = -EINVAL;
...@@ -143,27 +142,26 @@ static int update_usages_of_a_phandle_reference(struct device_node *node, ...@@ -143,27 +142,26 @@ static int update_usages_of_a_phandle_reference(struct device_node *node,
if (err) if (err)
goto err_fail; goto err_fail;
refnode = find_node_by_full_name(node, nodestr); refnode = find_node_by_full_name(overlay, node_path);
if (!refnode) if (!refnode)
continue; continue;
for_each_property_of_node(refnode, sprop) { for_each_property_of_node(refnode, prop) {
if (!of_prop_cmp(sprop->name, propstr)) if (!of_prop_cmp(prop->name, prop_name))
break; break;
} }
of_node_put(refnode); of_node_put(refnode);
if (!sprop) { if (!prop) {
err = -ENOENT; err = -ENOENT;
goto err_fail; goto err_fail;
} }
phandle = value; *(__be32 *)(prop->value + offset) = cpu_to_be32(phandle);
*(__be32 *)(sprop->value + offset) = cpu_to_be32(phandle);
} }
err_fail: err_fail:
kfree(propval); kfree(value);
return err; return err;
} }
...@@ -184,61 +182,61 @@ static int node_name_cmp(const struct device_node *dn1, ...@@ -184,61 +182,61 @@ static int node_name_cmp(const struct device_node *dn1,
* Does not take any devtree locks so make sure you call this on a tree * Does not take any devtree locks so make sure you call this on a tree
* which is at the detached state. * which is at the detached state.
*/ */
static int adjust_local_phandle_references(struct device_node *node, static int adjust_local_phandle_references(struct device_node *local_fixups,
struct device_node *target, int phandle_delta) struct device_node *overlay, int phandle_delta)
{ {
struct device_node *child, *childtarget; struct device_node *child, *overlay_child;
struct property *rprop, *sprop; struct property *prop_fix, *prop;
int err, i, count; int err, i, count;
unsigned int off; unsigned int off;
phandle phandle; phandle phandle;
if (!node) if (!local_fixups)
return 0; return 0;
for_each_property_of_node(node, rprop) { for_each_property_of_node(local_fixups, prop_fix) {
/* skip properties added automatically */ /* skip properties added automatically */
if (!of_prop_cmp(rprop->name, "name") || if (!of_prop_cmp(prop_fix->name, "name") ||
!of_prop_cmp(rprop->name, "phandle") || !of_prop_cmp(prop_fix->name, "phandle") ||
!of_prop_cmp(rprop->name, "linux,phandle")) !of_prop_cmp(prop_fix->name, "linux,phandle"))
continue; continue;
if ((rprop->length % 4) != 0 || rprop->length == 0) if ((prop_fix->length % 4) != 0 || prop_fix->length == 0)
return -EINVAL; return -EINVAL;
count = rprop->length / sizeof(__be32); count = prop_fix->length / sizeof(__be32);
for_each_property_of_node(target, sprop) { for_each_property_of_node(overlay, prop) {
if (!of_prop_cmp(sprop->name, rprop->name)) if (!of_prop_cmp(prop->name, prop_fix->name))
break; break;
} }
if (!sprop) if (!prop)
return -EINVAL; return -EINVAL;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
off = be32_to_cpu(((__be32 *)rprop->value)[i]); off = be32_to_cpu(((__be32 *)prop_fix->value)[i]);
if (off >= sprop->length || (off + 4) > sprop->length) if (off >= prop->length || (off + 4) > prop->length)
return -EINVAL; return -EINVAL;
if (phandle_delta) { if (phandle_delta) {
phandle = be32_to_cpu(*(__be32 *)(sprop->value + off)); phandle = be32_to_cpu(*(__be32 *)(prop->value + off));
phandle += phandle_delta; phandle += phandle_delta;
*(__be32 *)(sprop->value + off) = cpu_to_be32(phandle); *(__be32 *)(prop->value + off) = cpu_to_be32(phandle);
} }
} }
} }
for_each_child_of_node(node, child) { for_each_child_of_node(local_fixups, child) {
for_each_child_of_node(target, childtarget) for_each_child_of_node(overlay, overlay_child)
if (!node_name_cmp(child, childtarget)) if (!node_name_cmp(child, overlay_child))
break; break;
if (!childtarget) if (!overlay_child)
return -EINVAL; return -EINVAL;
err = adjust_local_phandle_references(child, childtarget, err = adjust_local_phandle_references(child, overlay_child,
phandle_delta); phandle_delta);
if (err) if (err)
return err; return err;
...@@ -260,78 +258,78 @@ static int adjust_local_phandle_references(struct device_node *node, ...@@ -260,78 +258,78 @@ static int adjust_local_phandle_references(struct device_node *node,
* are fit to be inserted or operate upon the live tree. * are fit to be inserted or operate upon the live tree.
* Returns 0 on success or a negative error value on error. * Returns 0 on success or a negative error value on error.
*/ */
int of_resolve_phandles(struct device_node *resolve) int of_resolve_phandles(struct device_node *overlay)
{ {
struct device_node *child, *childroot, *refnode; struct device_node *child, *local_fixups, *refnode;
struct device_node *root_sym, *resolve_sym, *resolve_fix; struct device_node *tree_symbols, *overlay_symbols, *overlay_fixups;
struct property *rprop; struct property *prop;
const char *refpath; const char *refpath;
phandle phandle, phandle_delta; phandle phandle, phandle_delta;
int err; int err;
if (!resolve) if (!overlay)
pr_err("%s: null node\n", __func__); pr_err("%s: null overlay\n", __func__);
if (resolve && !of_node_check_flag(resolve, OF_DETACHED)) if (overlay && !of_node_check_flag(overlay, OF_DETACHED))
pr_err("%s: node %s not detached\n", __func__, pr_err("%s: node %s not detached\n", __func__,
resolve->full_name); overlay->full_name);
if (!resolve || !of_node_check_flag(resolve, OF_DETACHED)) if (!overlay || !of_node_check_flag(overlay, OF_DETACHED))
return -EINVAL; return -EINVAL;
phandle_delta = live_tree_max_phandle() + 1; phandle_delta = live_tree_max_phandle() + 1;
adjust_overlay_phandles(resolve, phandle_delta); adjust_overlay_phandles(overlay, phandle_delta);
childroot = NULL; local_fixups = NULL;
for_each_child_of_node(resolve, childroot) for_each_child_of_node(overlay, local_fixups)
if (!of_node_cmp(childroot->name, "__local_fixups__")) if (!of_node_cmp(local_fixups->name, "__local_fixups__"))
break; break;
if (childroot != NULL) { if (local_fixups != NULL) {
err = adjust_local_phandle_references(childroot, err = adjust_local_phandle_references(local_fixups,
resolve, 0); overlay, 0);
if (err) if (err)
return err; return err;
BUG_ON(adjust_local_phandle_references(childroot, BUG_ON(adjust_local_phandle_references(local_fixups,
resolve, phandle_delta)); overlay, phandle_delta));
} }
root_sym = NULL; tree_symbols = NULL;
resolve_sym = NULL; overlay_symbols = NULL;
resolve_fix = NULL; overlay_fixups = NULL;
root_sym = of_find_node_by_path("/__symbols__"); tree_symbols = of_find_node_by_path("/__symbols__");
for_each_child_of_node(resolve, child) { for_each_child_of_node(overlay, child) {
if (!resolve_sym && !of_node_cmp(child->name, "__symbols__")) if (!overlay_symbols && !of_node_cmp(child->name, "__symbols__"))
resolve_sym = child; overlay_symbols = child;
if (!resolve_fix && !of_node_cmp(child->name, "__fixups__")) if (!overlay_fixups && !of_node_cmp(child->name, "__fixups__"))
resolve_fix = child; overlay_fixups = child;
if (resolve_sym && resolve_fix) if (overlay_symbols && overlay_fixups)
break; break;
} }
if (!resolve_fix) { if (!overlay_fixups) {
err = 0; err = 0;
goto out; goto out;
} }
if (!root_sym) { if (!tree_symbols) {
pr_err("%s: no symbols in root of device tree.\n", __func__); pr_err("%s: no symbols in root of device tree.\n", __func__);
err = -EINVAL; err = -EINVAL;
goto out; goto out;
} }
for_each_property_of_node(resolve_fix, rprop) { for_each_property_of_node(overlay_fixups, prop) {
/* skip properties added automatically */ /* skip properties added automatically */
if (!of_prop_cmp(rprop->name, "name")) if (!of_prop_cmp(prop->name, "name"))
continue; continue;
err = of_property_read_string(root_sym, err = of_property_read_string(tree_symbols,
rprop->name, &refpath); prop->name, &refpath);
if (err) if (err)
goto out; goto out;
...@@ -344,13 +342,13 @@ int of_resolve_phandles(struct device_node *resolve) ...@@ -344,13 +342,13 @@ int of_resolve_phandles(struct device_node *resolve)
phandle = refnode->phandle; phandle = refnode->phandle;
of_node_put(refnode); of_node_put(refnode);
err = update_usages_of_a_phandle_reference(resolve, rprop, phandle); err = update_usages_of_a_phandle_reference(overlay, prop, phandle);
if (err) if (err)
break; break;
} }
out: out:
of_node_put(root_sym); of_node_put(tree_symbols);
return err; return err;
} }
......
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