Skip to content

Commit 4e4694d

Browse files
mhiramatrostedt
authored andcommitted
bootconfig: Prohibit re-defining value on same key
Currently, bootconfig adds a new value on the existing key to the tail of an array. But this looks a bit confusing because an admin can easily rewrite the original value in the same config file. This rejects the following value re-definition. key = value1 ... key = value2 You should rewrite value1 to value2 in this case. Link: http://lkml.kernel.org/r/158227282199.12842.10110929876059658601.stgit@devnote2 Suggested-by: Steven Rostedt (VMware) <[email protected]> Signed-off-by: Masami Hiramatsu <[email protected]> [ Fixed spelling of arraies to arrays ] Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 88b9137 commit 4e4694d

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

Documentation/admin-guide/bootconfig.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,16 @@ Or more shorter, written as following::
6262
In both styles, same key words are automatically merged when parsing it
6363
at boot time. So you can append similar trees or key-values.
6464

65-
Note that a sub-key and a value can not co-exist under a parent key.
65+
Same-key Values
66+
---------------
67+
68+
It is prohibited that two or more values or arrays share a same-key.
69+
For example,::
70+
71+
foo = bar, baz
72+
foo = qux # !ERROR! we can not re-define same key
73+
74+
Also, a sub-key and a value can not co-exist under a parent key.
6675
For example, following config is NOT allowed.::
6776

6877
foo = value1

lib/bootconfig.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ static int __init __xbc_parse_keys(char *k)
581581
static int __init xbc_parse_kv(char **k, char *v)
582582
{
583583
struct xbc_node *prev_parent = last_parent;
584-
struct xbc_node *node, *child;
584+
struct xbc_node *child;
585585
char *next;
586586
int c, ret;
587587

@@ -590,15 +590,18 @@ static int __init xbc_parse_kv(char **k, char *v)
590590
return ret;
591591

592592
child = xbc_node_get_child(last_parent);
593-
if (child && xbc_node_is_key(child))
594-
return xbc_parse_error("Value is mixed with subkey", v);
593+
if (child) {
594+
if (xbc_node_is_key(child))
595+
return xbc_parse_error("Value is mixed with subkey", v);
596+
else
597+
return xbc_parse_error("Value is redefined", v);
598+
}
595599

596600
c = __xbc_parse_value(&v, &next);
597601
if (c < 0)
598602
return c;
599603

600-
node = xbc_add_sibling(v, XBC_VALUE);
601-
if (!node)
604+
if (!xbc_add_sibling(v, XBC_VALUE))
602605
return -ENOMEM;
603606

604607
if (c == ',') { /* Array */
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Same key value is not allowed
2+
key {
3+
foo = value
4+
bar = value2
5+
}
6+
key.foo = value

0 commit comments

Comments
 (0)