From: Masami Hiramatsu <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>,
Borislav Petkov <bp@alien8.de>,
LKML <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Peter Zijlstra <peterz@infradead.org>
Subject: [PATCH v3 1/2] bootconfig: Prohibit re-defining value on same key
Date: Fri, 21 Feb 2020 17:13:42 +0900 [thread overview]
Message-ID: <158227282199.12842.10110929876059658601.stgit@devnote2> (raw)
In-Reply-To: <158227281198.12842.8478910651170568606.stgit@devnote2>
Currently, bootconfig adds new value on the existing key
to the tail of an array. But this looks a bit confusing
because admin can rewrite original value in same config
file easily.
This rejects following value re-definition.
key = value1
...
key = value2
You should rewrite value1 to value2 in this case.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
Documentation/admin-guide/bootconfig.rst | 11 ++++++++++-
lib/bootconfig.c | 13 ++++++++-----
tools/bootconfig/samples/bad-samekey.bconf | 6 ++++++
3 files changed, 24 insertions(+), 6 deletions(-)
create mode 100644 tools/bootconfig/samples/bad-samekey.bconf
diff --git a/Documentation/admin-guide/bootconfig.rst b/Documentation/admin-guide/bootconfig.rst
index dfeffa73dca3..9ee7650b7817 100644
--- a/Documentation/admin-guide/bootconfig.rst
+++ b/Documentation/admin-guide/bootconfig.rst
@@ -62,7 +62,16 @@ Or more shorter, written as following::
In both styles, same key words are automatically merged when parsing it
at boot time. So you can append similar trees or key-values.
-Note that a sub-key and a value can not co-exist under a parent key.
+Same-key Values
+---------------
+
+It is prohibited that two or more values or arraies share a same-key.
+For example,::
+
+ foo = bar, baz
+ foo = qux # !ERROR! we can not re-define same key
+
+Also, a sub-key and a value can not co-exist under a parent key.
For example, following config is NOT allowed.::
foo = value1
diff --git a/lib/bootconfig.c b/lib/bootconfig.c
index 54ac623ca781..2ef304db31f2 100644
--- a/lib/bootconfig.c
+++ b/lib/bootconfig.c
@@ -581,7 +581,7 @@ static int __init __xbc_parse_keys(char *k)
static int __init xbc_parse_kv(char **k, char *v)
{
struct xbc_node *prev_parent = last_parent;
- struct xbc_node *node, *child;
+ struct xbc_node *child;
char *next;
int c, ret;
@@ -590,15 +590,18 @@ static int __init xbc_parse_kv(char **k, char *v)
return ret;
child = xbc_node_get_child(last_parent);
- if (child && xbc_node_is_key(child))
- return xbc_parse_error("Value is mixed with subkey", v);
+ if (child) {
+ if (xbc_node_is_key(child))
+ return xbc_parse_error("Value is mixed with subkey", v);
+ else
+ return xbc_parse_error("Value is redefined", v);
+ }
c = __xbc_parse_value(&v, &next);
if (c < 0)
return c;
- node = xbc_add_sibling(v, XBC_VALUE);
- if (!node)
+ if (!xbc_add_sibling(v, XBC_VALUE))
return -ENOMEM;
if (c == ',') { /* Array */
diff --git a/tools/bootconfig/samples/bad-samekey.bconf b/tools/bootconfig/samples/bad-samekey.bconf
new file mode 100644
index 000000000000..e8d983a4563c
--- /dev/null
+++ b/tools/bootconfig/samples/bad-samekey.bconf
@@ -0,0 +1,6 @@
+# Same key value is not allowed
+key {
+ foo = value
+ bar = value2
+}
+key.foo = value
next prev parent reply other threads:[~2020-02-21 8:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-21 8:13 [PATCH v3 0/2] bootconfig: Syntax updates Masami Hiramatsu
2020-02-21 8:13 ` Masami Hiramatsu [this message]
2020-02-22 4:20 ` [PATCH v3 1/2] bootconfig: Prohibit re-defining value on same key Randy Dunlap
2020-02-22 9:31 ` Geert Uytterhoeven
2020-02-22 14:41 ` Masami Hiramatsu
2020-02-22 16:24 ` Randy Dunlap
2020-02-21 8:13 ` [PATCH v3 2/2] bootconfig: Add append value operator support Masami Hiramatsu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=158227282199.12842.10110929876059658601.stgit@devnote2 \
--to=mhiramat@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bp@alien8.de \
--cc=geert@linux-m68k.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).