Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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) <rostedt@goodmis.org>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
[ Fixed spelling of arraies to arrays ]
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

authored by

Masami Hiramatsu and committed by
Steven Rostedt (VMware)
4e4694d8 88b91371

+24 -6
+10 -1
Documentation/admin-guide/bootconfig.rst
··· 62 62 In both styles, same key words are automatically merged when parsing it 63 63 at boot time. So you can append similar trees or key-values. 64 64 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. 66 75 For example, following config is NOT allowed.:: 67 76 68 77 foo = value1
+8 -5
lib/bootconfig.c
··· 581 581 static int __init xbc_parse_kv(char **k, char *v) 582 582 { 583 583 struct xbc_node *prev_parent = last_parent; 584 - struct xbc_node *node, *child; 584 + struct xbc_node *child; 585 585 char *next; 586 586 int c, ret; 587 587 ··· 590 590 return ret; 591 591 592 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); 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 + } 595 599 596 600 c = __xbc_parse_value(&v, &next); 597 601 if (c < 0) 598 602 return c; 599 603 600 - node = xbc_add_sibling(v, XBC_VALUE); 601 - if (!node) 604 + if (!xbc_add_sibling(v, XBC_VALUE)) 602 605 return -ENOMEM; 603 606 604 607 if (c == ',') { /* Array */
+6
tools/bootconfig/samples/bad-samekey.bconf
··· 1 + # Same key value is not allowed 2 + key { 3 + foo = value 4 + bar = value2 5 + } 6 + key.foo = value