Skip to content

Commit f962788

Browse files
committed
of: overlay: set node fields from properties when add new overlay node
Overlay nodes added by add_changeset_node() do not have the node fields name, phandle, and type set. The node passed to __of_attach_node() when the add node changeset entry is processed does not contain any properties. The node's properties are located in add property changeset entries that will be processed after the add node changeset is applied. Set the node's fields in the node contained in the add node changeset entry and do not set them to incorrect values in add_changeset_node(). A visible symptom that is fixed by this patch is the names of nodes added by overlays that have an entry in /sys/bus/platform/drivers/*/ will contain the unit-address but the node-name will be <NULL>, for example, "fc4ab000.<NULL>". After applying the patch the name, in this example, for node restart@fc4ab000 is "fc4ab000.restart". Tested-by: Alan Tull <atull@kernel.org> Signed-off-by: Frank Rowand <frank.rowand@sony.com>
1 parent 8c32965 commit f962788

2 files changed

Lines changed: 42 additions & 14 deletions

File tree

‎drivers/of/dynamic.c‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,24 @@ static void __of_attach_node(struct device_node *np)
205205
const __be32 *phandle;
206206
int sz;
207207

208-
np->name = __of_get_property(np, "name", NULL) ? : "<NULL>";
209-
np->type = __of_get_property(np, "device_type", NULL) ? : "<NULL>";
210-
211-
phandle = __of_get_property(np, "phandle", &sz);
212-
if (!phandle)
213-
phandle = __of_get_property(np, "linux,phandle", &sz);
214-
if (IS_ENABLED(CONFIG_PPC_PSERIES) && !phandle)
215-
phandle = __of_get_property(np, "ibm,phandle", &sz);
216-
np->phandle = (phandle && (sz >= 4)) ? be32_to_cpup(phandle) : 0;
208+
if (!of_node_check_flag(np, OF_OVERLAY)) {
209+
np->name = __of_get_property(np, "name", NULL);
210+
np->type = __of_get_property(np, "device_type", NULL);
211+
if (!np->name)
212+
np->name = "<NULL>";
213+
if (!np->type)
214+
np->type = "<NULL>";
215+
216+
phandle = __of_get_property(np, "phandle", &sz);
217+
if (!phandle)
218+
phandle = __of_get_property(np, "linux,phandle", &sz);
219+
if (IS_ENABLED(CONFIG_PPC_PSERIES) && !phandle)
220+
phandle = __of_get_property(np, "ibm,phandle", &sz);
221+
if (phandle && (sz >= 4))
222+
np->phandle = be32_to_cpup(phandle);
223+
else
224+
np->phandle = 0;
225+
}
217226

218227
np->child = NULL;
219228
np->sibling = np->parent->child;

‎drivers/of/overlay.c‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,11 @@ static int add_changeset_property(struct overlay_changeset *ovcs,
307307
int ret = 0;
308308
bool check_for_non_overlay_node = false;
309309

310-
if (!of_prop_cmp(overlay_prop->name, "name") ||
311-
!of_prop_cmp(overlay_prop->name, "phandle") ||
312-
!of_prop_cmp(overlay_prop->name, "linux,phandle"))
313-
return 0;
310+
if (target->in_livetree)
311+
if (!of_prop_cmp(overlay_prop->name, "name") ||
312+
!of_prop_cmp(overlay_prop->name, "phandle") ||
313+
!of_prop_cmp(overlay_prop->name, "linux,phandle"))
314+
return 0;
314315

315316
if (target->in_livetree)
316317
prop = of_find_property(target->np, overlay_prop->name, NULL);
@@ -330,6 +331,10 @@ static int add_changeset_property(struct overlay_changeset *ovcs,
330331

331332
if (!prop) {
332333
check_for_non_overlay_node = true;
334+
if (!target->in_livetree) {
335+
new_prop->next = target->np->deadprops;
336+
target->np->deadprops = new_prop;
337+
}
333338
ret = of_changeset_add_property(&ovcs->cset, target->np,
334339
new_prop);
335340
} else if (!of_prop_cmp(prop->name, "#address-cells")) {
@@ -400,9 +405,10 @@ static int add_changeset_node(struct overlay_changeset *ovcs,
400405
struct target *target, struct device_node *node)
401406
{
402407
const char *node_kbasename;
408+
const __be32 *phandle;
403409
struct device_node *tchild;
404410
struct target target_child;
405-
int ret = 0;
411+
int ret = 0, size;
406412

407413
node_kbasename = kbasename(node->full_name);
408414

@@ -416,6 +422,19 @@ static int add_changeset_node(struct overlay_changeset *ovcs,
416422
return -ENOMEM;
417423

418424
tchild->parent = target->np;
425+
tchild->name = __of_get_property(node, "name", NULL);
426+
tchild->type = __of_get_property(node, "device_type", NULL);
427+
428+
if (!tchild->name)
429+
tchild->name = "<NULL>";
430+
if (!tchild->type)
431+
tchild->type = "<NULL>";
432+
433+
/* ignore obsolete "linux,phandle" */
434+
phandle = __of_get_property(node, "phandle", &size);
435+
if (phandle && (size == 4))
436+
tchild->phandle = be32_to_cpup(phandle);
437+
419438
of_node_set_flag(tchild, OF_OVERLAY);
420439

421440
ret = of_changeset_attach_node(&ovcs->cset, tchild);

0 commit comments

Comments
 (0)