[PATCH 3/7] pxe_utils: extract per-entry key parsing into parse_label_keys()
Alexey Charkov
alchark at flipper.net
Thu Jun 4 17:31:08 CEST 2026
Split the body of parse_label() into a standalone parse_label_keys()
helper that walks key/value lines and populates a pre-existing
struct pxe_label. parse_label() becomes a thin wrapper that creates
the label, reads its name, attaches it to the menu, and delegates.
This is a pure refactor: the new helper contains the original loop
verbatim, with the local variable declarations moved to its scope.
No call sites or behaviour change.
A subsequent change will export this helper so callers parsing
formats that lack a 'label' header (notably Boot Loader Specification
type #2 entries) can populate a label directly from a file body
without duplicating the parser.
Signed-off-by: Alexey Charkov <alchark at flipper.net>
---
boot/pxe_utils.c | 58 ++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 37 insertions(+), 21 deletions(-)
diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
index c45c9d0cd012..420cee307baf 100644
--- a/boot/pxe_utils.c
+++ b/boot/pxe_utils.c
@@ -1288,34 +1288,20 @@ static int parse_label_kernel(char **c, struct pxe_label *label)
}
/*
- * Parses a label and adds it to the list of labels for a menu.
- *
- * A label ends when we either get to the end of a file, or
- * get some input we otherwise don't have a handler defined
- * for.
+ * Parse the body of a label: the sequence of key/value lines that follow
+ * the 'label NAME' header. Stops at end-of-file or at a token that doesn't
+ * belong inside a label (which is pushed back so the caller can handle it).
*
+ * Returns 1 on success, < 0 on error.
*/
-static int parse_label(char **c, struct pxe_menu *cfg)
+static int parse_label_keys(char **c, struct pxe_menu *cfg,
+ struct pxe_label *label)
{
struct token t;
+ char *s;
int len;
- char *s = *c;
- struct pxe_label *label;
int err;
- label = label_create();
- if (!label)
- return -ENOMEM;
-
- err = parse_sliteral(c, &label->name);
- if (err < 0) {
- printf("Expected label name: %.*s\n", (int)(*c - s), s);
- label_destroy(label);
- return -EINVAL;
- }
-
- list_add_tail(&label->list, &cfg->labels);
-
while (1) {
s = *c;
get_token(c, &t, L_KEYWORD);
@@ -1397,6 +1383,36 @@ static int parse_label(char **c, struct pxe_menu *cfg)
}
}
+/*
+ * Parses a label and adds it to the list of labels for a menu.
+ *
+ * A label ends when we either get to the end of a file, or
+ * get some input we otherwise don't have a handler defined
+ * for.
+ *
+ */
+static int parse_label(char **c, struct pxe_menu *cfg)
+{
+ char *s = *c;
+ struct pxe_label *label;
+ int err;
+
+ label = label_create();
+ if (!label)
+ return -ENOMEM;
+
+ err = parse_sliteral(c, &label->name);
+ if (err < 0) {
+ printf("Expected label name: %.*s\n", (int)(*c - s), s);
+ label_destroy(label);
+ return -EINVAL;
+ }
+
+ list_add_tail(&label->list, &cfg->labels);
+
+ return parse_label_keys(c, cfg, label);
+}
+
/*
* This 16 comes from the limit pxelinux imposes on nested includes.
*
--
2.53.0
More information about the U-Boot
mailing list