aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flattree.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/flattree.c b/flattree.c
index 95e43d3..1bcd808 100644
--- a/flattree.c
+++ b/flattree.c
@@ -604,11 +604,11 @@ static void flat_realign(struct inbuf *inb, int align)
die("Premature end of data parsing flat device tree\n");
}
-static char *flat_read_string(struct inbuf *inb)
+static const char *flat_read_string(struct inbuf *inb)
{
int len = 0;
const char *p = inb->ptr;
- char *str;
+ const char *str;
do {
if (p >= inb->limit)
@@ -616,7 +616,7 @@ static char *flat_read_string(struct inbuf *inb)
len++;
} while ((*p++) != '\0');
- str = xstrdup(inb->ptr);
+ str = inb->ptr;
inb->ptr += len;
@@ -711,7 +711,7 @@ static struct reserve_info *flat_read_mem_reserve(struct inbuf *inb)
}
-static char *nodename_from_path(const char *ppath, const char *cpath)
+static const char *nodename_from_path(const char *ppath, const char *cpath)
{
int plen;
@@ -725,7 +725,7 @@ static char *nodename_from_path(const char *ppath, const char *cpath)
if (!streq(ppath, "/"))
plen++;
- return xstrdup(cpath + plen);
+ return cpath + plen;
}
static struct node *unflatten_tree(struct inbuf *dtbuf,
@@ -733,7 +733,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
const char *parent_flatname, int flags)
{
struct node *node;
- char *flatname;
+ const char *flatname;
uint32_t val;
node = build_node(NULL, NULL, NULL);
@@ -741,9 +741,10 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
flatname = flat_read_string(dtbuf);
if (flags & FTF_FULLPATH)
- node->name = nodename_from_path(parent_flatname, flatname);
+ node->name = xstrdup(nodename_from_path(parent_flatname,
+ flatname));
else
- node->name = flatname;
+ node->name = xstrdup(flatname);
do {
struct property *prop;
@@ -785,10 +786,6 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
}
} while (val != FDT_END_NODE);
- if (node->name != flatname) {
- free(flatname);
- }
-
return node;
}