Skip to content

Commit

Permalink
Revert "annotations: add positions"
Browse files Browse the repository at this point in the history
This reverts commit baa1d2c.

Turns out this introduced memory badness.  valgrind picks it up on
x86, but it straight out SEGVs on x86.

Signed-off-by: David Gibson <[email protected]>
  • Loading branch information
dgibson committed Nov 14, 2018
1 parent 403cc79 commit a3143fa
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 67 deletions.
13 changes: 5 additions & 8 deletions dtc-parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,7 @@ devicetree:
*/
if (!($<flags>-1 & DTSF_PLUGIN))
ERROR(&@2, "Label or path %s not found", $1);
$$ = add_orphan_node(
name_node(build_node(NULL, NULL, NULL),
""),
$2, $1);
$$ = add_orphan_node(name_node(build_node(NULL, NULL), ""), $2, $1);
}
| devicetree DT_LABEL dt_ref nodedef
{
Expand Down Expand Up @@ -263,7 +260,7 @@ devicetree:
nodedef:
'{' proplist subnodes '}' ';'
{
$$ = build_node($2, $3, &@$);
$$ = build_node($2, $3);
}
;

Expand All @@ -281,11 +278,11 @@ proplist:
propdef:
DT_PROPNODENAME '=' propdata ';'
{
$$ = build_property($1, $3, &@$);
$$ = build_property($1, $3);
}
| DT_PROPNODENAME ';'
{
$$ = build_property($1, empty_data, &@$);
$$ = build_property($1, empty_data);
}
| DT_DEL_PROP DT_PROPNODENAME ';'
{
Expand Down Expand Up @@ -566,7 +563,7 @@ subnode:
}
| DT_DEL_NODE DT_PROPNODENAME ';'
{
$$ = name_node(build_node_delete(&@$), $2);
$$ = name_node(build_node_delete(), $2);
}
| DT_OMIT_NO_REF subnode
{
Expand Down
10 changes: 3 additions & 7 deletions dtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ struct property {
struct property *next;

struct label *labels;
struct srcpos *srcpos;
};

struct node {
Expand All @@ -178,7 +177,6 @@ struct node {

struct label *labels;
const struct bus_type *bus;
struct srcpos *srcpos;

bool omit_if_unused, is_referenced;
};
Expand Down Expand Up @@ -207,15 +205,13 @@ struct node {
void add_label(struct label **labels, char *label);
void delete_labels(struct label **labels);

struct property *build_property(char *name, struct data val,
struct srcpos *srcpos);
struct property *build_property(char *name, struct data val);
struct property *build_property_delete(char *name);
struct property *chain_property(struct property *first, struct property *list);
struct property *reverse_properties(struct property *first);

struct node *build_node(struct property *proplist, struct node *children,
struct srcpos *srcpos);
struct node *build_node_delete(struct srcpos *srcpos);
struct node *build_node(struct property *proplist, struct node *children);
struct node *build_node_delete(void);
struct node *name_node(struct node *node, char *name);
struct node *omit_node_if_unused(struct node *node);
struct node *reference_node(struct node *node);
Expand Down
4 changes: 2 additions & 2 deletions flattree.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ static struct property *flat_read_property(struct inbuf *dtbuf,

val = flat_read_data(dtbuf, proplen);

return build_property(name, val, NULL);
return build_property(name, val);
}


Expand Down Expand Up @@ -750,7 +750,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
char *flatname;
uint32_t val;

node = build_node(NULL, NULL, NULL);
node = build_node(NULL, NULL);

flatname = flat_read_string(dtbuf);

Expand Down
5 changes: 2 additions & 3 deletions fstree.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static struct node *read_fstree(const char *dirname)
if (!d)
die("Couldn't opendir() \"%s\": %s\n", dirname, strerror(errno));

tree = build_node(NULL, NULL, NULL);
tree = build_node(NULL, NULL);

while ((de = readdir(d)) != NULL) {
char *tmpname;
Expand All @@ -60,8 +60,7 @@ static struct node *read_fstree(const char *dirname)
} else {
prop = build_property(xstrdup(de->d_name),
data_copy_file(pfile,
st.st_size),
NULL);
st.st_size));
add_property(tree, prop);
fclose(pfile);
}
Expand Down
33 changes: 11 additions & 22 deletions livetree.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/

#include "dtc.h"
#include "srcpos.h"

/*
* Tree building functions
Expand Down Expand Up @@ -51,16 +50,14 @@ void delete_labels(struct label **labels)
label->deleted = 1;
}

struct property *build_property(char *name, struct data val,
struct srcpos *srcpos)
struct property *build_property(char *name, struct data val)
{
struct property *new = xmalloc(sizeof(*new));

memset(new, 0, sizeof(*new));

new->name = name;
new->val = val;
new->srcpos = srcpos_copy(srcpos);

return new;
}
Expand Down Expand Up @@ -100,8 +97,7 @@ struct property *reverse_properties(struct property *first)
return head;
}

struct node *build_node(struct property *proplist, struct node *children,
struct srcpos *srcpos)
struct node *build_node(struct property *proplist, struct node *children)
{
struct node *new = xmalloc(sizeof(*new));
struct node *child;
Expand All @@ -110,7 +106,6 @@ struct node *build_node(struct property *proplist, struct node *children,

new->proplist = reverse_properties(proplist);
new->children = children;
new->srcpos = srcpos_copy(srcpos);

for_each_child(new, child) {
child->parent = new;
Expand All @@ -119,14 +114,13 @@ struct node *build_node(struct property *proplist, struct node *children,
return new;
}

struct node *build_node_delete(struct srcpos *srcpos)
struct node *build_node_delete(void)
{
struct node *new = xmalloc(sizeof(*new));

memset(new, 0, sizeof(*new));

new->deleted = 1;
new->srcpos = srcpos_copy(srcpos);

return new;
}
Expand Down Expand Up @@ -189,8 +183,6 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)

old_prop->val = new_prop->val;
old_prop->deleted = 0;
free(old_prop->srcpos);
old_prop->srcpos = new_prop->srcpos;
free(new_prop);
new_prop = NULL;
break;
Expand Down Expand Up @@ -231,8 +223,6 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)
add_child(old_node, new_child);
}

old_node->srcpos = srcpos_extend(old_node->srcpos, new_node->srcpos);

/* The new node contents are now merged into the old node. Free
* the new node. */
free(new_node);
Expand All @@ -251,18 +241,18 @@ struct node * add_orphan_node(struct node *dt, struct node *new_node, char *ref)
if (ref[0] == '/') {
d = data_append_data(d, ref, strlen(ref) + 1);

p = build_property("target-path", d, NULL);
p = build_property("target-path", d);
} else {
d = data_add_marker(d, REF_PHANDLE, ref);
d = data_append_integer(d, 0xffffffff, 32);

p = build_property("target", d, NULL);
p = build_property("target", d);
}

xasprintf(&name, "fragment@%u",
next_orphan_fragment++);
name_node(new_node, "__overlay__");
node = build_node(p, new_node, NULL);
node = build_node(p, new_node);
name_node(node, name);

add_child(dt, node);
Expand Down Expand Up @@ -361,7 +351,7 @@ void append_to_property(struct node *node,
p->val = d;
} else {
d = data_append_data(empty_data, data, len);
p = build_property(name, d, NULL);
p = build_property(name, d);
add_property(node, p);
}
}
Expand Down Expand Up @@ -619,11 +609,11 @@ cell_t get_node_phandle(struct node *root, struct node *node)

if (!get_property(node, "linux,phandle")
&& (phandle_format & PHANDLE_LEGACY))
add_property(node, build_property("linux,phandle", d, NULL));
add_property(node, build_property("linux,phandle", d));

if (!get_property(node, "phandle")
&& (phandle_format & PHANDLE_EPAPR))
add_property(node, build_property("phandle", d, NULL));
add_property(node, build_property("phandle", d));

/* If the node *does* have a phandle property, we must
* be dealing with a self-referencing phandle, which will be
Expand Down Expand Up @@ -797,7 +787,7 @@ static struct node *build_and_name_child_node(struct node *parent, char *name)
{
struct node *node;

node = build_node(NULL, NULL, NULL);
node = build_node(NULL, NULL);
name_node(node, xstrdup(name));
add_child(parent, node);

Expand Down Expand Up @@ -859,8 +849,7 @@ static void generate_label_tree_internal(struct dt_info *dti,
/* insert it */
p = build_property(l->label,
data_copy_mem(node->fullpath,
strlen(node->fullpath) + 1),
NULL);
strlen(node->fullpath) + 1));
add_property(an, p);
}

Expand Down
22 changes: 0 additions & 22 deletions srcpos.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ struct srcpos srcpos_empty = {
.last_line = 0,
.last_column = 0,
.file = NULL,
.next = NULL,
};

void srcpos_update(struct srcpos *pos, const char *text, int len)
Expand Down Expand Up @@ -235,34 +234,13 @@ struct srcpos *
srcpos_copy(struct srcpos *pos)
{
struct srcpos *pos_new;
struct srcfile_state *srcfile_state;

if (!pos)
return NULL;

pos_new = xmalloc(sizeof(struct srcpos));
memcpy(pos_new, pos, sizeof(struct srcpos));

/* allocate without free */
srcfile_state = xmalloc(sizeof(struct srcfile_state));
memcpy(srcfile_state, pos->file, sizeof(struct srcfile_state));
pos_new->file = srcfile_state;

return pos_new;
}

struct srcpos *srcpos_extend(struct srcpos *pos, struct srcpos *newtail)
{
struct srcpos *p;

if (!pos)
return newtail;

for (p = pos; p->next != NULL; p = p->next);
p->next = newtail;
return pos;
}

char *
srcpos_string(struct srcpos *pos)
{
Expand Down
3 changes: 0 additions & 3 deletions srcpos.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ struct srcpos {
int last_line;
int last_column;
struct srcfile_state *file;
struct srcpos *next;
};

#define YYLTYPE struct srcpos
Expand Down Expand Up @@ -106,8 +105,6 @@ extern struct srcpos srcpos_empty;

extern void srcpos_update(struct srcpos *pos, const char *text, int len);
extern struct srcpos *srcpos_copy(struct srcpos *pos);
extern struct srcpos *srcpos_extend(struct srcpos *new_srcpos,
struct srcpos *old_srcpos);
extern char *srcpos_string(struct srcpos *pos);

extern void PRINTF(3, 0) srcpos_verror(struct srcpos *pos, const char *prefix,
Expand Down

0 comments on commit a3143fa

Please sign in to comment.