U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Alexey Charkov <alchark@flipper.net>
To: u-boot@lists.denx.de
Cc: Tom Rini <trini@konsulko.com>,
	 "Kory Maincent (TI.com)" <kory.maincent@bootlin.com>,
	 Simon Glass <sjg@chromium.org>,
	Hugo Villeneuve <hvilleneuve@dimonoff.com>,
	 Andrew Goodbody <andrew.goodbody@linaro.org>,
	 Quentin Schulz <quentin.schulz@cherry.de>,
	Anshul Dalal <anshuld@ti.com>,  Peng Fan <peng.fan@nxp.com>,
	Martin Schwan <m.schwan@phytec.de>,
	 Daniel Golle <daniel@makrotopia.org>,
	 Mattijs Korpershoek <mkorpershoek@kernel.org>,
	 Alexey Charkov <alchark@flipper.net>
Subject: [PATCH 3/7] pxe_utils: extract per-entry key parsing into parse_label_keys()
Date: Thu, 04 Jun 2026 19:31:08 +0400	[thread overview]
Message-ID: <20260604-bls-v1-3-4ce6d1ee4711@flipper.net> (raw)
In-Reply-To: <20260604-bls-v1-0-4ce6d1ee4711@flipper.net>

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@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


  parent reply	other threads:[~2026-06-04 15:31 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-04 15:31 [PATCH 0/7] pxe_utils: small fixups, implement BLS type 1 boot on top of them Alexey Charkov
2026-06-04 15:31 ` [PATCH 1/7] pxe_utils: fix W=1 kernel-doc warnings Alexey Charkov
2026-06-04 16:05   ` Tom Rini
2026-06-25 15:25   ` Simon Glass
2026-06-25 15:28   ` Simon Glass
2026-06-04 15:31 ` [PATCH 2/7] pxe_utils: accept "options" as synonym for "append" Alexey Charkov
2026-06-04 16:06   ` Tom Rini
2026-06-04 15:31 ` Alexey Charkov [this message]
2026-06-04 16:06   ` [PATCH 3/7] pxe_utils: extract per-entry key parsing into parse_label_keys() Tom Rini
2026-06-18 15:12   ` Simon Glass
2026-06-25 15:28   ` Simon Glass
2026-06-25 15:55     ` Alexey Charkov
2026-06-04 15:31 ` [PATCH 4/7] pxe_utils: export per-entry label helpers Alexey Charkov
2026-06-04 15:31 ` [PATCH 5/7] pxe_utils: optionally ignore unknown keys in parse_label_keys() Alexey Charkov
2026-06-04 15:31 ` [PATCH 6/7] pxe_utils: accept "title" inside a label as a synonym for "menu label" Alexey Charkov
2026-06-04 15:31 ` [PATCH 7/7] boot: add a minimal bootmeth for the Boot Loader Specification Alexey Charkov
2026-06-12 18:24   ` Simon Glass
2026-06-25 15:28   ` Simon Glass
2026-06-25 15:51     ` Alexey Charkov
2026-06-25 16:24       ` Simon Glass
2026-06-25 16:57         ` Alexey Charkov
2026-06-25 17:24           ` Tom Rini
2026-06-25 17:29             ` Simon Glass
2026-06-25 17:32               ` Tom Rini
2026-06-26 10:45                 ` Simon Glass
2026-06-26 13:47                   ` Tom Rini
2026-06-29  5:45                     ` Simon Glass
2026-06-29 14:24                       ` Tom Rini
2026-06-25 17:25           ` Simon Glass
2026-06-04 16:05 ` [PATCH 0/7] pxe_utils: small fixups, implement BLS type 1 boot on top of them Tom Rini
2026-06-04 17:16   ` Alexey Charkov
2026-06-04 17:21     ` Tom Rini
2026-06-04 17:35       ` Alexey Charkov
2026-06-12 18:23         ` Simon Glass

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=20260604-bls-v1-3-4ce6d1ee4711@flipper.net \
    --to=alchark@flipper.net \
    --cc=andrew.goodbody@linaro.org \
    --cc=anshuld@ti.com \
    --cc=daniel@makrotopia.org \
    --cc=hvilleneuve@dimonoff.com \
    --cc=kory.maincent@bootlin.com \
    --cc=m.schwan@phytec.de \
    --cc=mkorpershoek@kernel.org \
    --cc=peng.fan@nxp.com \
    --cc=quentin.schulz@cherry.de \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /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