[PATCH 1/4] bootconfig: return 0 from xbc_snprint_cmdline() for a leaf root
From: Breno Leitao
Date: Wed May 27 2026 - 12:43:37 EST
Returning -EINVAL when @root has no descendant key nodes is a quirky
result for a renderer: "nothing to render" is not an error. The only
existing caller, xbc_make_cmdline(), papers over it with a `len <= 0`
check, so the misbehavior is harmless today. The new -C user in
tools/bootconfig added by the follow-up patches propagates the error
and turns an empty "kernel {}" subtree into a build failure.
Short-circuit the leaf-root case and return 0 so the rendered length
matches the rendered content.
Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
---
lib/bootconfig.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/lib/bootconfig.c b/lib/bootconfig.c
index f445b7703fdd..3a102c9122f7 100644
--- a/lib/bootconfig.c
+++ b/lib/bootconfig.c
@@ -431,6 +431,16 @@ int __init xbc_snprint_cmdline(char *buf, size_t size, struct xbc_node *root)
const char *val, *q;
int ret;
+ /*
+ * A leaf @root (e.g. an empty "kernel {}" subtree, or a key whose
+ * only child is a value node) has no descendant key/value pairs to
+ * render. The leaf-finding iterator below would otherwise return
+ * @root itself, which xbc_node_compose_key_after() rejects with
+ * -EINVAL.
+ */
+ if (root && xbc_node_is_leaf(root))
+ return 0;
+
xbc_node_for_each_key_value(root, knode, val) {
ret = xbc_node_compose_key_after(root, knode,
xbc_namebuf, XBC_KEYLEN_MAX);
--
2.54.0