From: Eduardo Mucelli Rezende Oliveira <edumucelli@gmail.com>
To: mhiramat@kernel.org
Cc: akpm@linux-foundation.org, rostedt@goodmis.org,
linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] tools/bootconfig: Close only opened braces in compact output
Date: Tue, 10 Nov 2026 19:05:59 +0100 [thread overview]
Message-ID: <f2bad80ef771708417b75bf7f1286f9f2521ee97.1794333957.git.edumucelli@gmail.com> (raw)
In-Reply-To: <cover.1794333957.git.edumucelli@gmail.com>
A key may have both a value and subkeys. When it has only one subkey,
xbc_show_compact_tree() can print that subkey using dotted notation
without opening a brace. During backtracking, however, it treats the
value node followed by a subkey as evidence that a brace was opened.
For example, a.b=v, a.b.c=w and a.z=q are printed with the brace for a
closed before z. Reading that output back changes a.z into the root key
z, silently changing the configuration.
Remember the nodes for which opening braces were actually printed and
close a brace only when backtracking through the matching node. Extend
the existing mixed-value/subkey sample to cover a sibling after a valued
parent with one subkey.
Fixes: e5efaeb8a8f5 ("bootconfig: Support mixing a value and subkeys under a key")
Signed-off-by: Eduardo Mucelli Rezende Oliveira <edumucelli@gmail.com>
---
With this valid configuration:
a.b = v
a.b.c = w
a.z = q
the original compact output closes the brace for a before printing z.
Reparsing it turns a.z into the root key z. Values and subkeys under
the same key are allowed by the documented syntax:
https://docs.kernel.org/admin-guide/bootconfig.html#same-key-values
I checked parser round trips for valued parents, bare subkeys, arrays,
deeper trees and a test initrd image. All 94 focused checks pass with
the fix, independently and in the combined series. The full bootconfig
test suite also passes.
tools/bootconfig/main.c | 15 +++++++--------
tools/bootconfig/samples/exp-good-mixed-kv1.bconf | 5 +++++
tools/bootconfig/samples/good-mixed-kv1.bconf | 5 +++++
3 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
index 56d76bdeaa09..1bab0e685e2d 100644
--- a/tools/bootconfig/main.c
+++ b/tools/bootconfig/main.c
@@ -71,6 +71,7 @@ static int xbc_show_value(struct xbc_node *node, bool semicolon)
static void xbc_show_compact_tree(void)
{
struct xbc_node *node, *cnode = NULL, *vnode;
+ struct xbc_node *parent[XBC_DEPTH_MAX];
int depth = 0, i;
node = xbc_root_node();
@@ -100,7 +101,7 @@ static void xbc_show_compact_tree(void)
}
if (cnode && xbc_node_is_key(cnode)) {
printf("%s {\n", xbc_node_get_data(node));
- depth++;
+ parent[depth++] = node;
node = cnode;
cnode = NULL;
continue;
@@ -128,14 +129,12 @@ static void xbc_show_compact_tree(void)
node = xbc_node_get_parent(node);
if (!node)
return;
- if (!xbc_node_get_child(node)->next)
+ if (!depth || parent[depth - 1] != node)
continue;
- if (depth) {
- depth--;
- for (i = 0; i < depth; i++)
- printf("\t");
- printf("}\n");
- }
+ depth--;
+ for (i = 0; i < depth; i++)
+ printf("\t");
+ printf("}\n");
}
node = xbc_node_get_next(node);
}
diff --git a/tools/bootconfig/samples/exp-good-mixed-kv1.bconf b/tools/bootconfig/samples/exp-good-mixed-kv1.bconf
index 8346287d9251..0b8b2f59da31 100644
--- a/tools/bootconfig/samples/exp-good-mixed-kv1.bconf
+++ b/tools/bootconfig/samples/exp-good-mixed-kv1.bconf
@@ -1,2 +1,7 @@
key = "value";
key.subkey = "another-value";
+a {
+ b = "v";
+ b.c = "w";
+ z = "q";
+}
diff --git a/tools/bootconfig/samples/good-mixed-kv1.bconf b/tools/bootconfig/samples/good-mixed-kv1.bconf
index 1761547dd05c..35442ee62b75 100644
--- a/tools/bootconfig/samples/good-mixed-kv1.bconf
+++ b/tools/bootconfig/samples/good-mixed-kv1.bconf
@@ -1,3 +1,8 @@
# value -> subkey pattern
key = value
key.subkey = another-value
+
+# A valued parent with one subkey must not close its enclosing brace.
+a.b = v
+a.b.c = w
+a.z = q
--
2.53.0
next prev parent reply other threads:[~2026-11-10 18:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 18:05 [PATCH 0/3] bootconfig: Preserve values and key paths during parsing and output Eduardo Mucelli Rezende Oliveira
2026-11-10 18:05 ` Eduardo Mucelli Rezende Oliveira [this message]
2026-11-10 18:06 ` [PATCH 2/3] bootconfig: Trim unquoted values at end of file Eduardo Mucelli Rezende Oliveira
2026-11-10 18:06 ` [PATCH 3/3] tools/bootconfig: Preserve values containing both types of quotes Eduardo Mucelli Rezende Oliveira
2026-11-10 19:08 ` [PATCH v2 0/3] bootconfig: Preserve values and key paths during parsing and output Eduardo Mucelli Rezende Oliveira
2026-11-10 19:08 ` [PATCH v2 1/3] tools/bootconfig: Close only opened braces in compact output Eduardo Mucelli Rezende Oliveira
2026-11-10 19:08 ` [PATCH v2 2/3] bootconfig: Trim unquoted values at end of file Eduardo Mucelli Rezende Oliveira
2026-11-10 19:08 ` [PATCH v2 3/3] tools/bootconfig: Preserve values containing both types of quotes Eduardo Mucelli Rezende Oliveira
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=f2bad80ef771708417b75bf7f1286f9f2521ee97.1794333957.git.edumucelli@gmail.com \
--to=edumucelli@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.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
all inboxes | Powered by JetHome®