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 v2 5/8] bootconfig: Reject subkey and value on same parent key
Date: Thu, 20 Feb 2020 21:19:12 +0900 [thread overview]
Message-ID: <158220115232.26565.7792340045009731803.stgit@devnote2> (raw)
In-Reply-To: <158220110257.26565.4812934676257459744.stgit@devnote2>
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.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
Documentation/admin-guide/bootconfig.rst | 7 +++++++
lib/bootconfig.c | 16 ++++++++++++----
tools/bootconfig/samples/bad-mixed-kv1.bconf | 3 +++
tools/bootconfig/samples/bad-mixed-kv2.bconf | 3 +++
4 files changed, 25 insertions(+), 4 deletions(-)
create mode 100644 tools/bootconfig/samples/bad-mixed-kv1.bconf
create mode 100644 tools/bootconfig/samples/bad-mixed-kv2.bconf
diff --git a/Documentation/admin-guide/bootconfig.rst b/Documentation/admin-guide/bootconfig.rst
index 48675052c963..4a106584eb21 100644
--- a/Documentation/admin-guide/bootconfig.rst
+++ b/Documentation/admin-guide/bootconfig.rst
@@ -62,6 +62,13 @@ 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.
+For example, following config is NOT allowed.::
+
+ foo = value1
+ foo.bar = value2 # !ERROR! subkey "bar" and value "value1" can NOT co-exist
+
+
Comments
--------
diff --git a/lib/bootconfig.c b/lib/bootconfig.c
index 3ea601a2eba5..54ac623ca781 100644
--- a/lib/bootconfig.c
+++ b/lib/bootconfig.c
@@ -533,7 +533,7 @@ struct xbc_node *find_match_node(struct xbc_node *node, char *k)
static int __init __xbc_add_key(char *k)
{
- struct xbc_node *node;
+ struct xbc_node *node, *child;
if (!xbc_valid_keyword(k))
return xbc_parse_error("Invalid keyword", k);
@@ -543,8 +543,12 @@ static int __init __xbc_add_key(char *k)
if (!last_parent) /* the first level */
node = find_match_node(xbc_nodes, k);
- else
- node = find_match_node(xbc_node_get_child(last_parent), k);
+ else {
+ child = xbc_node_get_child(last_parent);
+ if (child && xbc_node_is_value(child))
+ return xbc_parse_error("Subkey is mixed with value", k);
+ node = find_match_node(child, k);
+ }
if (node)
last_parent = node;
@@ -577,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;
+ struct xbc_node *node, *child;
char *next;
int c, ret;
@@ -585,6 +589,10 @@ static int __init xbc_parse_kv(char **k, char *v)
if (ret)
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);
+
c = __xbc_parse_value(&v, &next);
if (c < 0)
return c;
diff --git a/tools/bootconfig/samples/bad-mixed-kv1.bconf b/tools/bootconfig/samples/bad-mixed-kv1.bconf
new file mode 100644
index 000000000000..1761547dd05c
--- /dev/null
+++ b/tools/bootconfig/samples/bad-mixed-kv1.bconf
@@ -0,0 +1,3 @@
+# value -> subkey pattern
+key = value
+key.subkey = another-value
diff --git a/tools/bootconfig/samples/bad-mixed-kv2.bconf b/tools/bootconfig/samples/bad-mixed-kv2.bconf
new file mode 100644
index 000000000000..6b32e0c3878c
--- /dev/null
+++ b/tools/bootconfig/samples/bad-mixed-kv2.bconf
@@ -0,0 +1,3 @@
+# subkey -> value pattern
+key.subkey = value
+key = another-value
next prev parent reply other threads:[~2020-02-20 12:19 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-20 12:18 [PATCH v2 0/8] bootconfig: Update for the recent reports Masami Hiramatsu
2020-02-20 12:18 ` [PATCH v2 1/8] bootconfig: Set CONFIG_BOOT_CONFIG=n by default Masami Hiramatsu
2020-02-27 9:22 ` Geert Uytterhoeven
2020-02-27 14:27 ` Steven Rostedt
2020-02-27 14:47 ` Geert Uytterhoeven
2020-02-27 15:05 ` Steven Rostedt
2020-02-20 12:18 ` [PATCH v2 2/8] bootconfig: Add bootconfig magic word for indicating bootconfig explicitly Masami Hiramatsu
2020-02-20 12:18 ` [PATCH v2 3/8] tools/bootconfig: Remove unneeded error message silencer Masami Hiramatsu
2020-02-20 12:19 ` [PATCH v2 4/8] bootconfig: Remove unneeded checksum Masami Hiramatsu
2020-02-20 17:14 ` Steven Rostedt
2020-02-20 23:34 ` Masami Hiramatsu
2020-02-20 12:19 ` Masami Hiramatsu [this message]
2020-02-20 12:19 ` [PATCH v2 6/8] bootconfig: Overwrite value on same key by default Masami Hiramatsu
2020-02-20 17:16 ` Steven Rostedt
2020-02-21 0:21 ` Masami Hiramatsu
2020-02-21 2:56 ` Steven Rostedt
2020-02-21 6:32 ` Masami Hiramatsu
2020-02-20 12:19 ` [PATCH v2 7/8] bootconfig: Add append value operator support Masami Hiramatsu
2020-02-20 12:19 ` [PATCH v2 8/8] bootconfig: Print array as multiple commands for legacy command line 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=158220115232.26565.7792340045009731803.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).