Skip to content

Commit 597c0e3

Browse files
mhiramatrostedt
authored andcommitted
bootconfig: Add more parse error messages
Add more error messages for following cases. - Exceeding max number of nodes - Config tree data is empty (e.g. comment only) - Config data is empty or exceeding max size - bootconfig is already initialized Link: http://lkml.kernel.org/r/158091060401.27924.9024818742827122764.stgit@devnote2 Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent e241d14 commit 597c0e3

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/bootconfig.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ static struct xbc_node * __init xbc_add_sibling(char *data, u32 flag)
373373
sib->next = xbc_node_index(node);
374374
}
375375
}
376-
}
376+
} else
377+
xbc_parse_error("Too many nodes", data);
377378

378379
return node;
379380
}
@@ -657,8 +658,10 @@ static int __init xbc_verify_tree(void)
657658
struct xbc_node *n, *m;
658659

659660
/* Empty tree */
660-
if (xbc_node_num == 0)
661+
if (xbc_node_num == 0) {
662+
xbc_parse_error("Empty config", xbc_data);
661663
return -ENOENT;
664+
}
662665

663666
for (i = 0; i < xbc_node_num; i++) {
664667
if (xbc_nodes[i].next > xbc_node_num) {
@@ -732,12 +735,17 @@ int __init xbc_init(char *buf)
732735
char *p, *q;
733736
int ret, c;
734737

735-
if (xbc_data)
738+
if (xbc_data) {
739+
pr_err("Error: bootconfig is already initialized.\n");
736740
return -EBUSY;
741+
}
737742

738743
ret = strlen(buf);
739-
if (ret > XBC_DATA_MAX - 1 || ret == 0)
744+
if (ret > XBC_DATA_MAX - 1 || ret == 0) {
745+
pr_err("Error: Config data is %s.\n",
746+
ret ? "too big" : "empty");
740747
return -ERANGE;
748+
}
741749

742750
xbc_data = buf;
743751
xbc_data_size = ret + 1;

0 commit comments

Comments
 (0)