Skip to content

Commit a7e4cfb

Browse files
committed
of/fdt: only store the device node basename in full_name
With dependencies on a statically allocated full path name converted to use %pOF format specifier, we can store just the basename of node, and the unflattening of the FDT can be simplified. This commit will affect the remaining users of full_name. After analyzing these users, the remaining cases should only change some print messages. The main users of full_name are providing a name for struct resource. The resource names shouldn't be important other than providing /proc/iomem names. We no longer distinguish between pre and post 0x10 dtb formats as either a full path or basename will work. However, less than 0x10 formats have been broken since the conversion to use libfdt (and no one has cared). The conversion of the unflattening code to be non-recursive also broke pre 0x10 formats as the populate_node function would return 0 in that case. Signed-off-by: Rob Herring <robh@kernel.org>
1 parent 0666598 commit a7e4cfb

1 file changed

Lines changed: 11 additions & 58 deletions

File tree

‎drivers/of/fdt.c‎

Lines changed: 11 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -266,74 +266,32 @@ static void populate_properties(const void *blob,
266266
*pprev = NULL;
267267
}
268268

269-
static unsigned int populate_node(const void *blob,
270-
int offset,
271-
void **mem,
272-
struct device_node *dad,
273-
unsigned int fpsize,
274-
struct device_node **pnp,
275-
bool dryrun)
269+
static bool populate_node(const void *blob,
270+
int offset,
271+
void **mem,
272+
struct device_node *dad,
273+
struct device_node **pnp,
274+
bool dryrun)
276275
{
277276
struct device_node *np;
278277
const char *pathp;
279278
unsigned int l, allocl;
280-
int new_format = 0;
281279

282280
pathp = fdt_get_name(blob, offset, &l);
283281
if (!pathp) {
284282
*pnp = NULL;
285-
return 0;
283+
return false;
286284
}
287285

288286
allocl = ++l;
289287

290-
/* version 0x10 has a more compact unit name here instead of the full
291-
* path. we accumulate the full path size using "fpsize", we'll rebuild
292-
* it later. We detect this because the first character of the name is
293-
* not '/'.
294-
*/
295-
if ((*pathp) != '/') {
296-
new_format = 1;
297-
if (fpsize == 0) {
298-
/* root node: special case. fpsize accounts for path
299-
* plus terminating zero. root node only has '/', so
300-
* fpsize should be 2, but we want to avoid the first
301-
* level nodes to have two '/' so we use fpsize 1 here
302-
*/
303-
fpsize = 1;
304-
allocl = 2;
305-
l = 1;
306-
pathp = "";
307-
} else {
308-
/* account for '/' and path size minus terminal 0
309-
* already in 'l'
310-
*/
311-
fpsize += l;
312-
allocl = fpsize;
313-
}
314-
}
315-
316288
np = unflatten_dt_alloc(mem, sizeof(struct device_node) + allocl,
317289
__alignof__(struct device_node));
318290
if (!dryrun) {
319291
char *fn;
320292
of_node_init(np);
321293
np->full_name = fn = ((char *)np) + sizeof(*np);
322-
if (new_format) {
323-
/* rebuild full path for new format */
324-
if (dad && dad->parent) {
325-
strcpy(fn, dad->full_name);
326-
#ifdef DEBUG
327-
if ((strlen(fn) + l + 1) != allocl) {
328-
pr_debug("%s: p: %d, l: %d, a: %d\n",
329-
pathp, (int)strlen(fn),
330-
l, allocl);
331-
}
332-
#endif
333-
fn += strlen(fn);
334-
}
335-
*(fn++) = '/';
336-
}
294+
337295
memcpy(fn, pathp, l);
338296

339297
if (dad != NULL) {
@@ -355,7 +313,7 @@ static unsigned int populate_node(const void *blob,
355313
}
356314

357315
*pnp = np;
358-
return fpsize;
316+
return true;
359317
}
360318

361319
static void reverse_nodes(struct device_node *parent)
@@ -399,7 +357,6 @@ static int unflatten_dt_nodes(const void *blob,
399357
struct device_node *root;
400358
int offset = 0, depth = 0, initial_depth = 0;
401359
#define FDT_MAX_DEPTH 64
402-
unsigned int fpsizes[FDT_MAX_DEPTH];
403360
struct device_node *nps[FDT_MAX_DEPTH];
404361
void *base = mem;
405362
bool dryrun = !base;
@@ -418,7 +375,6 @@ static int unflatten_dt_nodes(const void *blob,
418375
depth = initial_depth = 1;
419376

420377
root = dad;
421-
fpsizes[depth] = dad ? strlen(of_node_full_name(dad)) : 0;
422378
nps[depth] = dad;
423379

424380
for (offset = 0;
@@ -427,11 +383,8 @@ static int unflatten_dt_nodes(const void *blob,
427383
if (WARN_ON_ONCE(depth >= FDT_MAX_DEPTH))
428384
continue;
429385

430-
fpsizes[depth+1] = populate_node(blob, offset, &mem,
431-
nps[depth],
432-
fpsizes[depth],
433-
&nps[depth+1], dryrun);
434-
if (!fpsizes[depth+1])
386+
if (!populate_node(blob, offset, &mem, nps[depth],
387+
&nps[depth+1], dryrun))
435388
return mem - base;
436389

437390
if (!dryrun && nodepp && !*nodepp)

0 commit comments

Comments
 (0)