Skip to content

Commit b89dae1

Browse files
frowandrobherring
authored andcommitted
of: overlay: do not include path in full_name of added nodes
Struct device_node full_name no longer includes the full path name when the devicetree is created from a flattened device tree (FDT). The overlay node creation code was not modified to reflect this change. Fix the node full_name generated by overlay code to contain only the basename. Unittests call an overlay internal function to create new nodes. Fix up these calls to provide basename only instead of the full path. Fixes: a7e4cfb ("of/fdt: only store the device node basename in full_name") Signed-off-by: Frank Rowand <frank.rowand@sony.com> Signed-off-by: Rob Herring <robh@kernel.org>
1 parent a4f91f0 commit b89dae1

4 files changed

Lines changed: 30 additions & 18 deletions

File tree

‎drivers/of/dynamic.c‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -383,25 +383,24 @@ struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags)
383383

384384
/**
385385
* __of_node_dup() - Duplicate or create an empty device node dynamically.
386-
* @fmt: Format string (plus vargs) for new full name of the device node
386+
* @np: if not NULL, contains properties to be duplicated in new node
387+
* @full_name: string value to be duplicated into new node's full_name field
387388
*
388-
* Create an device tree node, either by duplicating an empty node or by allocating
389-
* an empty one suitable for further modification. The node data are
390-
* dynamically allocated and all the node flags have the OF_DYNAMIC &
391-
* OF_DETACHED bits set. Returns the newly allocated node or NULL on out of
392-
* memory error.
389+
* Create a device tree node, optionally duplicating the properties of
390+
* another node. The node data are dynamically allocated and all the node
391+
* flags have the OF_DYNAMIC & OF_DETACHED bits set.
392+
*
393+
* Returns the newly allocated node or NULL on out of memory error.
393394
*/
394-
struct device_node *__of_node_dup(const struct device_node *np, const char *fmt, ...)
395+
struct device_node *__of_node_dup(const struct device_node *np,
396+
const char *full_name)
395397
{
396-
va_list vargs;
397398
struct device_node *node;
398399

399400
node = kzalloc(sizeof(*node), GFP_KERNEL);
400401
if (!node)
401402
return NULL;
402-
va_start(vargs, fmt);
403-
node->full_name = kvasprintf(GFP_KERNEL, fmt, vargs);
404-
va_end(vargs);
403+
node->full_name = kstrdup(full_name, GFP_KERNEL);
405404
if (!node->full_name) {
406405
kfree(node);
407406
return NULL;

‎drivers/of/of_private.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ extern void *__unflatten_device_tree(const void *blob,
104104
* own the devtree lock or work on detached trees only.
105105
*/
106106
struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags);
107-
__printf(2, 3) struct device_node *__of_node_dup(const struct device_node *np, const char *fmt, ...);
107+
struct device_node *__of_node_dup(const struct device_node *np,
108+
const char *full_name);
108109

109110
struct device_node *__of_find_node_by_path(struct device_node *parent,
110111
const char *path);

‎drivers/of/overlay.c‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,20 @@ static int add_changeset_property(struct overlay_changeset *ovcs,
312312
* If @node has child nodes, add the children recursively via
313313
* build_changeset_next_level().
314314
*
315-
* NOTE: Multiple mods of created nodes not supported.
315+
* NOTE_1: A live devicetree created from a flattened device tree (FDT) will
316+
* not contain the full path in node->full_name. Thus an overlay
317+
* created from an FDT also will not contain the full path in
318+
* node->full_name. However, a live devicetree created from Open
319+
* Firmware may have the full path in node->full_name.
320+
*
321+
* add_changeset_node() follows the FDT convention and does not include
322+
* the full path in node->full_name. Even though it expects the overlay
323+
* to not contain the full path, it uses kbasename() to remove the
324+
* full path should it exist. It also uses kbasename() in comparisons
325+
* to nodes in the live devicetree so that it can apply an overlay to
326+
* a live devicetree created from Open Firmware.
327+
*
328+
* NOTE_2: Multiple mods of created nodes not supported.
316329
* If more than one fragment contains a node that does not already exist
317330
* in the live tree, then for each fragment of_changeset_attach_node()
318331
* will add a changeset entry to add the node. When the changeset is
@@ -339,8 +352,7 @@ static int add_changeset_node(struct overlay_changeset *ovcs,
339352
break;
340353

341354
if (!tchild) {
342-
tchild = __of_node_dup(node, "%pOF/%s",
343-
target_node, node_kbasename);
355+
tchild = __of_node_dup(node, node_kbasename);
344356
if (!tchild)
345357
return -ENOMEM;
346358

‎drivers/of/unittest.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,13 +692,13 @@ static void __init of_unittest_changeset(void)
692692
struct device_node *n1, *n2, *n21, *nchangeset, *nremove, *parent, *np;
693693
struct of_changeset chgset;
694694

695-
n1 = __of_node_dup(NULL, "/testcase-data/changeset/n1");
695+
n1 = __of_node_dup(NULL, "n1");
696696
unittest(n1, "testcase setup failure\n");
697697

698-
n2 = __of_node_dup(NULL, "/testcase-data/changeset/n2");
698+
n2 = __of_node_dup(NULL, "n2");
699699
unittest(n2, "testcase setup failure\n");
700700

701-
n21 = __of_node_dup(NULL, "%s/%s", "/testcase-data/changeset/n2", "n21");
701+
n21 = __of_node_dup(NULL, "n21");
702702
unittest(n21, "testcase setup failure %p\n", n21);
703703

704704
nchangeset = of_find_node_by_path("/testcase-data/changeset");

0 commit comments

Comments
 (0)