Commit a7e4cfb0 authored by Rob Herring's avatar Rob Herring

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: default avatarRob Herring <robh@kernel.org>
parent 06665989
...@@ -266,74 +266,32 @@ static void populate_properties(const void *blob, ...@@ -266,74 +266,32 @@ static void populate_properties(const void *blob,
*pprev = NULL; *pprev = NULL;
} }
static unsigned int populate_node(const void *blob, static bool populate_node(const void *blob,
int offset, int offset,
void **mem, void **mem,
struct device_node *dad, struct device_node *dad,
unsigned int fpsize, struct device_node **pnp,
struct device_node **pnp, bool dryrun)
bool dryrun)
{ {
struct device_node *np; struct device_node *np;
const char *pathp; const char *pathp;
unsigned int l, allocl; unsigned int l, allocl;
int new_format = 0;
pathp = fdt_get_name(blob, offset, &l); pathp = fdt_get_name(blob, offset, &l);
if (!pathp) { if (!pathp) {
*pnp = NULL; *pnp = NULL;
return 0; return false;
} }
allocl = ++l; allocl = ++l;
/* version 0x10 has a more compact unit name here instead of the full
* path. we accumulate the full path size using "fpsize", we'll rebuild
* it later. We detect this because the first character of the name is
* not '/'.
*/
if ((*pathp) != '/') {
new_format = 1;
if (fpsize == 0) {
/* root node: special case. fpsize accounts for path
* plus terminating zero. root node only has '/', so
* fpsize should be 2, but we want to avoid the first
* level nodes to have two '/' so we use fpsize 1 here
*/
fpsize = 1;
allocl = 2;
l = 1;
pathp = "";
} else {
/* account for '/' and path size minus terminal 0
* already in 'l'
*/
fpsize += l;
allocl = fpsize;
}
}
np = unflatten_dt_alloc(mem, sizeof(struct device_node) + allocl, np = unflatten_dt_alloc(mem, sizeof(struct device_node) + allocl,
__alignof__(struct device_node)); __alignof__(struct device_node));
if (!dryrun) { if (!dryrun) {
char *fn; char *fn;
of_node_init(np); of_node_init(np);
np->full_name = fn = ((char *)np) + sizeof(*np); np->full_name = fn = ((char *)np) + sizeof(*np);
if (new_format) {
/* rebuild full path for new format */
if (dad && dad->parent) {
strcpy(fn, dad->full_name);
#ifdef DEBUG
if ((strlen(fn) + l + 1) != allocl) {
pr_debug("%s: p: %d, l: %d, a: %d\n",
pathp, (int)strlen(fn),
l, allocl);
}
#endif
fn += strlen(fn);
}
*(fn++) = '/';
}
memcpy(fn, pathp, l); memcpy(fn, pathp, l);
if (dad != NULL) { if (dad != NULL) {
...@@ -355,7 +313,7 @@ static unsigned int populate_node(const void *blob, ...@@ -355,7 +313,7 @@ static unsigned int populate_node(const void *blob,
} }
*pnp = np; *pnp = np;
return fpsize; return true;
} }
static void reverse_nodes(struct device_node *parent) static void reverse_nodes(struct device_node *parent)
...@@ -399,7 +357,6 @@ static int unflatten_dt_nodes(const void *blob, ...@@ -399,7 +357,6 @@ static int unflatten_dt_nodes(const void *blob,
struct device_node *root; struct device_node *root;
int offset = 0, depth = 0, initial_depth = 0; int offset = 0, depth = 0, initial_depth = 0;
#define FDT_MAX_DEPTH 64 #define FDT_MAX_DEPTH 64
unsigned int fpsizes[FDT_MAX_DEPTH];
struct device_node *nps[FDT_MAX_DEPTH]; struct device_node *nps[FDT_MAX_DEPTH];
void *base = mem; void *base = mem;
bool dryrun = !base; bool dryrun = !base;
...@@ -418,7 +375,6 @@ static int unflatten_dt_nodes(const void *blob, ...@@ -418,7 +375,6 @@ static int unflatten_dt_nodes(const void *blob,
depth = initial_depth = 1; depth = initial_depth = 1;
root = dad; root = dad;
fpsizes[depth] = dad ? strlen(of_node_full_name(dad)) : 0;
nps[depth] = dad; nps[depth] = dad;
for (offset = 0; for (offset = 0;
...@@ -427,11 +383,8 @@ static int unflatten_dt_nodes(const void *blob, ...@@ -427,11 +383,8 @@ static int unflatten_dt_nodes(const void *blob,
if (WARN_ON_ONCE(depth >= FDT_MAX_DEPTH)) if (WARN_ON_ONCE(depth >= FDT_MAX_DEPTH))
continue; continue;
fpsizes[depth+1] = populate_node(blob, offset, &mem, if (!populate_node(blob, offset, &mem, nps[depth],
nps[depth], &nps[depth+1], dryrun))
fpsizes[depth],
&nps[depth+1], dryrun);
if (!fpsizes[depth+1])
return mem - base; return mem - base;
if (!dryrun && nodepp && !*nodepp) if (!dryrun && nodepp && !*nodepp)
......
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