Commit 1e408966 authored by Frank Rowand's avatar Frank Rowand Committed by Rob Herring

of: overlay: rename variables to be consistent

Variables change name across function calls when there is not a good
reason to do so.  Fix by changing "fdt" to "new_fdt" and "tree" to
"overlay_root".

The name disparity was confusing when creating the following commit.
The name changes are in this separate commit to make review of the
following commmit less complex.
Signed-off-by: default avatarFrank Rowand <frank.rowand@sony.com>
Signed-off-by: default avatarRob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/20220420222505.928492-2-frowand.list@gmail.com
parent 5f756a2e
...@@ -57,8 +57,8 @@ struct fragment { ...@@ -57,8 +57,8 @@ struct fragment {
* struct overlay_changeset * struct overlay_changeset
* @id: changeset identifier * @id: changeset identifier
* @ovcs_list: list on which we are located * @ovcs_list: list on which we are located
* @fdt: base of memory allocated to hold aligned FDT that was unflattened to create @overlay_tree * @new_fdt: Memory allocated to hold unflattened aligned FDT
* @overlay_tree: expanded device tree that contains the fragment nodes * @overlay_root: expanded device tree that contains the fragment nodes
* @count: count of fragment structures * @count: count of fragment structures
* @fragments: fragment nodes in the overlay expanded device tree * @fragments: fragment nodes in the overlay expanded device tree
* @symbols_fragment: last element of @fragments[] is the __symbols__ node * @symbols_fragment: last element of @fragments[] is the __symbols__ node
...@@ -67,8 +67,8 @@ struct fragment { ...@@ -67,8 +67,8 @@ struct fragment {
struct overlay_changeset { struct overlay_changeset {
int id; int id;
struct list_head ovcs_list; struct list_head ovcs_list;
const void *fdt; const void *new_fdt;
struct device_node *overlay_tree; struct device_node *overlay_root;
int count; int count;
struct fragment *fragments; struct fragment *fragments;
bool symbols_fragment; bool symbols_fragment;
...@@ -183,7 +183,7 @@ static int overlay_notify(struct overlay_changeset *ovcs, ...@@ -183,7 +183,7 @@ static int overlay_notify(struct overlay_changeset *ovcs,
/* /*
* The values of properties in the "/__symbols__" node are paths in * The values of properties in the "/__symbols__" node are paths in
* the ovcs->overlay_tree. When duplicating the properties, the paths * the ovcs->overlay_root. When duplicating the properties, the paths
* need to be adjusted to be the correct path for the live device tree. * need to be adjusted to be the correct path for the live device tree.
* *
* The paths refer to a node in the subtree of a fragment node's "__overlay__" * The paths refer to a node in the subtree of a fragment node's "__overlay__"
...@@ -219,7 +219,7 @@ static struct property *dup_and_fixup_symbol_prop( ...@@ -219,7 +219,7 @@ static struct property *dup_and_fixup_symbol_prop(
if (path_len < 1) if (path_len < 1)
return NULL; return NULL;
fragment_node = __of_find_node_by_path(ovcs->overlay_tree, path + 1); fragment_node = __of_find_node_by_path(ovcs->overlay_root, path + 1);
overlay_node = __of_find_node_by_path(fragment_node, "__overlay__/"); overlay_node = __of_find_node_by_path(fragment_node, "__overlay__/");
of_node_put(fragment_node); of_node_put(fragment_node);
of_node_put(overlay_node); of_node_put(overlay_node);
...@@ -716,19 +716,20 @@ static struct device_node *find_target(struct device_node *info_node) ...@@ -716,19 +716,20 @@ static struct device_node *find_target(struct device_node *info_node)
/** /**
* init_overlay_changeset() - initialize overlay changeset from overlay tree * init_overlay_changeset() - initialize overlay changeset from overlay tree
* @ovcs: Overlay changeset to build * @ovcs: Overlay changeset to build
* @fdt: base of memory allocated to hold aligned FDT that was unflattened to create @tree * @new_fdt: Memory allocated to hold unflattened aligned FDT
* @tree: Contains the overlay fragments and overlay fixup nodes * @overlay_root: Contains the overlay fragments and overlay fixup nodes
* *
* Initialize @ovcs. Populate @ovcs->fragments with node information from * Initialize @ovcs. Populate @ovcs->fragments with node information from
* the top level of @tree. The relevant top level nodes are the fragment * the top level of @overlay_root. The relevant top level nodes are the
* nodes and the __symbols__ node. Any other top level node will be ignored. * fragment nodes and the __symbols__ node. Any other top level node will
* be ignored.
* *
* Return: 0 on success, -ENOMEM if memory allocation failure, -EINVAL if error * Return: 0 on success, -ENOMEM if memory allocation failure, -EINVAL if error
* detected in @tree, or -ENOSPC if idr_alloc() error. * detected in @overlay_root, or -ENOSPC if idr_alloc() error.
*/ */
static int init_overlay_changeset(struct overlay_changeset *ovcs, static int init_overlay_changeset(struct overlay_changeset *ovcs,
const void *fdt, struct device_node *tree) const void *new_fdt, struct device_node *overlay_root)
{ {
struct device_node *node, *overlay_node; struct device_node *node, *overlay_node;
struct fragment *fragment; struct fragment *fragment;
...@@ -739,17 +740,17 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs, ...@@ -739,17 +740,17 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs,
* Warn for some issues. Can not return -EINVAL for these until * Warn for some issues. Can not return -EINVAL for these until
* of_unittest_apply_overlay() is fixed to pass these checks. * of_unittest_apply_overlay() is fixed to pass these checks.
*/ */
if (!of_node_check_flag(tree, OF_DYNAMIC)) if (!of_node_check_flag(overlay_root, OF_DYNAMIC))
pr_debug("%s() tree is not dynamic\n", __func__); pr_debug("%s() overlay_root is not dynamic\n", __func__);
if (!of_node_check_flag(tree, OF_DETACHED)) if (!of_node_check_flag(overlay_root, OF_DETACHED))
pr_debug("%s() tree is not detached\n", __func__); pr_debug("%s() overlay_root is not detached\n", __func__);
if (!of_node_is_root(tree)) if (!of_node_is_root(overlay_root))
pr_debug("%s() tree is not root\n", __func__); pr_debug("%s() overlay_root is not root\n", __func__);
ovcs->overlay_tree = tree; ovcs->overlay_root = overlay_root;
ovcs->fdt = fdt; ovcs->new_fdt = new_fdt;
INIT_LIST_HEAD(&ovcs->ovcs_list); INIT_LIST_HEAD(&ovcs->ovcs_list);
...@@ -762,7 +763,7 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs, ...@@ -762,7 +763,7 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs,
cnt = 0; cnt = 0;
/* fragment nodes */ /* fragment nodes */
for_each_child_of_node(tree, node) { for_each_child_of_node(overlay_root, node) {
overlay_node = of_get_child_by_name(node, "__overlay__"); overlay_node = of_get_child_by_name(node, "__overlay__");
if (overlay_node) { if (overlay_node) {
cnt++; cnt++;
...@@ -770,7 +771,7 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs, ...@@ -770,7 +771,7 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs,
} }
} }
node = of_get_child_by_name(tree, "__symbols__"); node = of_get_child_by_name(overlay_root, "__symbols__");
if (node) { if (node) {
cnt++; cnt++;
of_node_put(node); of_node_put(node);
...@@ -783,7 +784,7 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs, ...@@ -783,7 +784,7 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs,
} }
cnt = 0; cnt = 0;
for_each_child_of_node(tree, node) { for_each_child_of_node(overlay_root, node) {
overlay_node = of_get_child_by_name(node, "__overlay__"); overlay_node = of_get_child_by_name(node, "__overlay__");
if (!overlay_node) if (!overlay_node)
continue; continue;
...@@ -805,7 +806,7 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs, ...@@ -805,7 +806,7 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs,
* if there is a symbols fragment in ovcs->fragments[i] it is * if there is a symbols fragment in ovcs->fragments[i] it is
* the final element in the array * the final element in the array
*/ */
node = of_get_child_by_name(tree, "__symbols__"); node = of_get_child_by_name(overlay_root, "__symbols__");
if (node) { if (node) {
ovcs->symbols_fragment = 1; ovcs->symbols_fragment = 1;
fragment = &fragments[cnt]; fragment = &fragments[cnt];
...@@ -859,12 +860,12 @@ static void free_overlay_changeset(struct overlay_changeset *ovcs) ...@@ -859,12 +860,12 @@ static void free_overlay_changeset(struct overlay_changeset *ovcs)
} }
kfree(ovcs->fragments); kfree(ovcs->fragments);
/* /*
* There should be no live pointers into ovcs->overlay_tree and * There should be no live pointers into ovcs->overlay_root and
* ovcs->fdt due to the policy that overlay notifiers are not allowed * ovcs->new_fdt due to the policy that overlay notifiers are not
* to retain pointers into the overlay devicetree. * allowed to retain pointers into the overlay devicetree.
*/ */
kfree(ovcs->overlay_tree); kfree(ovcs->overlay_root);
kfree(ovcs->fdt); kfree(ovcs->new_fdt);
kfree(ovcs); kfree(ovcs);
} }
...@@ -872,16 +873,15 @@ static void free_overlay_changeset(struct overlay_changeset *ovcs) ...@@ -872,16 +873,15 @@ static void free_overlay_changeset(struct overlay_changeset *ovcs)
* internal documentation * internal documentation
* *
* of_overlay_apply() - Create and apply an overlay changeset * of_overlay_apply() - Create and apply an overlay changeset
* @fdt: base of memory allocated to hold the aligned FDT * @new_fdt: Memory allocated to hold the aligned FDT
* @tree: Expanded overlay device tree * @overlay_root: Expanded overlay device tree
* @ovcs_id: Pointer to overlay changeset id * @ovcs_id: Pointer to overlay changeset id
* *
* Creates and applies an overlay changeset. * Creates and applies an overlay changeset.
* *
* If an error occurs in a pre-apply notifier, then no changes are made * If an error occurs in a pre-apply notifier, then no changes are made
* to the device tree. * to the device tree.
* *
* A non-zero return value will not have created the changeset if error is from: * A non-zero return value will not have created the changeset if error is from:
* - parameter checks * - parameter checks
* - building the changeset * - building the changeset
...@@ -911,8 +911,8 @@ static void free_overlay_changeset(struct overlay_changeset *ovcs) ...@@ -911,8 +911,8 @@ static void free_overlay_changeset(struct overlay_changeset *ovcs)
* id is returned to *ovcs_id. * id is returned to *ovcs_id.
*/ */
static int of_overlay_apply(const void *fdt, struct device_node *tree, static int of_overlay_apply(const void *new_fdt,
int *ovcs_id) struct device_node *overlay_root, int *ovcs_id)
{ {
struct overlay_changeset *ovcs; struct overlay_changeset *ovcs;
int ret = 0, ret_revert, ret_tmp; int ret = 0, ret_revert, ret_tmp;
...@@ -924,16 +924,16 @@ static int of_overlay_apply(const void *fdt, struct device_node *tree, ...@@ -924,16 +924,16 @@ static int of_overlay_apply(const void *fdt, struct device_node *tree,
if (devicetree_corrupt()) { if (devicetree_corrupt()) {
pr_err("devicetree state suspect, refuse to apply overlay\n"); pr_err("devicetree state suspect, refuse to apply overlay\n");
kfree(fdt); kfree(new_fdt);
kfree(tree); kfree(overlay_root);
ret = -EBUSY; ret = -EBUSY;
goto out; goto out;
} }
ovcs = kzalloc(sizeof(*ovcs), GFP_KERNEL); ovcs = kzalloc(sizeof(*ovcs), GFP_KERNEL);
if (!ovcs) { if (!ovcs) {
kfree(fdt); kfree(new_fdt);
kfree(tree); kfree(overlay_root);
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
...@@ -941,20 +941,20 @@ static int of_overlay_apply(const void *fdt, struct device_node *tree, ...@@ -941,20 +941,20 @@ static int of_overlay_apply(const void *fdt, struct device_node *tree,
of_overlay_mutex_lock(); of_overlay_mutex_lock();
mutex_lock(&of_mutex); mutex_lock(&of_mutex);
ret = of_resolve_phandles(tree); ret = of_resolve_phandles(overlay_root);
if (ret) if (ret)
goto err_free_tree; goto err_free_tree;
ret = init_overlay_changeset(ovcs, fdt, tree); ret = init_overlay_changeset(ovcs, new_fdt, overlay_root);
if (ret) if (ret)
goto err_free_tree; goto err_free_tree;
/* /*
* after overlay_notify(), ovcs->overlay_tree related pointers may have * After overlay_notify(), ovcs->overlay_root related pointers may have
* leaked to drivers, so can not kfree() tree, aka ovcs->overlay_tree; * leaked to drivers, so can not kfree() tree, aka ovcs->overlay_tree;
* and can not free memory containing aligned fdt. The aligned fdt * and can not free memory containing aligned fdt. The aligned fdt
* is contained within the memory at ovcs->fdt, possibly at an offset * is contained within the memory at ovcs->new_fdt, possibly at an
* from ovcs->fdt. * offset from ovcs->new_fdt.
*/ */
ret = overlay_notify(ovcs, OF_OVERLAY_PRE_APPLY); ret = overlay_notify(ovcs, OF_OVERLAY_PRE_APPLY);
if (ret) { if (ret) {
...@@ -996,8 +996,8 @@ static int of_overlay_apply(const void *fdt, struct device_node *tree, ...@@ -996,8 +996,8 @@ static int of_overlay_apply(const void *fdt, struct device_node *tree,
goto out_unlock; goto out_unlock;
err_free_tree: err_free_tree:
kfree(fdt); kfree(new_fdt);
kfree(tree); kfree(overlay_root);
err_free_overlay_changeset: err_free_overlay_changeset:
free_overlay_changeset(ovcs); free_overlay_changeset(ovcs);
......
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