Skip to content

Commit a24d286

Browse files
mhiramatrostedt
authored andcommitted
bootconfig: Reject subkey and value on same parent key
Reject if a value node is mixed with subkey node on same parent key node. A value node can not co-exist with subkey node under some key node, e.g. key = value key.subkey = another-value This is not be allowed because bootconfig API is not designed to handle such case. Link: http://lkml.kernel.org/r/158220115232.26565.7792340045009731803.stgit@devnote2 Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 15e9503 commit a24d286

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

Documentation/admin-guide/bootconfig.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ 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.
66+
For example, following config is NOT allowed.::
67+
68+
foo = value1
69+
foo.bar = value2 # !ERROR! subkey "bar" and value "value1" can NOT co-exist
70+
71+
6572
Comments
6673
--------
6774

lib/bootconfig.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ struct xbc_node *find_match_node(struct xbc_node *node, char *k)
533533

534534
static int __init __xbc_add_key(char *k)
535535
{
536-
struct xbc_node *node;
536+
struct xbc_node *node, *child;
537537

538538
if (!xbc_valid_keyword(k))
539539
return xbc_parse_error("Invalid keyword", k);
@@ -543,8 +543,12 @@ static int __init __xbc_add_key(char *k)
543543

544544
if (!last_parent) /* the first level */
545545
node = find_match_node(xbc_nodes, k);
546-
else
547-
node = find_match_node(xbc_node_get_child(last_parent), k);
546+
else {
547+
child = xbc_node_get_child(last_parent);
548+
if (child && xbc_node_is_value(child))
549+
return xbc_parse_error("Subkey is mixed with value", k);
550+
node = find_match_node(child, k);
551+
}
548552

549553
if (node)
550554
last_parent = node;
@@ -577,14 +581,18 @@ static int __init __xbc_parse_keys(char *k)
577581
static int __init xbc_parse_kv(char **k, char *v)
578582
{
579583
struct xbc_node *prev_parent = last_parent;
580-
struct xbc_node *node;
584+
struct xbc_node *node, *child;
581585
char *next;
582586
int c, ret;
583587

584588
ret = __xbc_parse_keys(*k);
585589
if (ret)
586590
return ret;
587591

592+
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);
595+
588596
c = __xbc_parse_value(&v, &next);
589597
if (c < 0)
590598
return c;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# value -> subkey pattern
2+
key = value
3+
key.subkey = another-value
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# subkey -> value pattern
2+
key.subkey = value
3+
key = another-value

0 commit comments

Comments
 (0)