From patchwork Sat Jan 10 20:28:43 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1457 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768077012; bh=ooeb4UOIPFESr06RGaHibIaBgqcNB2aCui3O7EkSM6U=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=B2xV0rvw5qyCgNQDbxUhKk8wYSX9OENVxtocFZcUUDoTtO5+A5D7WoU0aiqAySp/4 xP8XGivKgZ/pELlMJ7Btcx0MBokclNrhrHmKyOn4U9kbFeYxG+bk1ZiOUN23Q/SQ9c afvccX5j8lRA5wACNFFMr1/Ru95th191TPhk/SXKdExVcRwKDtdzutjhq4WpoktX1a 4E2iK8GF9/ohnqj27+vii87LptphIaL+o0BauqsJ9PFaMbtgPMm2zmM8PgObDSxj/A Iwl6zLrME+azyvgRuH27QFkNcd9NeXqLVssBsAjKAHxIaRPi/ZFN3XxzN8MNSZjaDb W2eazBwxorKJA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7564C69186 for ; Sat, 10 Jan 2026 13:30:12 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id vl4RwYAaE97g for ; Sat, 10 Jan 2026 13:30:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768077011; bh=ooeb4UOIPFESr06RGaHibIaBgqcNB2aCui3O7EkSM6U=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=oeI/lgwyTLDkZuTWi1gHC/MRT7qlKbmJr9ZUotEs+4ZevT6lnUIqad0HqmcAoEgvR txVrStAfrZzJlgOBDNa3mS3Bm5E5fWNt/lE8AeMO1U6SIsyv4PY1O/Pl7/pA4tDDXY Y4M246JHjkQKr73gil8Exu1PMnMVq7wMzdVJoz+L+Bx6nFQ+ubmVdWzFlWczetA6az Z7MIfAg8wmAfPDrIuRaw7nHp+8jt4+hU9QPvAdZzQ+QId9nnfdP1JfCU0qxDNtJpg6 wzL3AQ0K2Hb29w8pUt9/IsRXF3VEE6DijjcQOTxF+lrig6lrsNkoQk4oXn1EWhlOOi j18zjxQSgzXUw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 01BD669290 for ; Sat, 10 Jan 2026 13:30:11 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768077008; bh=C9m6aPC19sG9G+ZZllqlzkO2IJohMUBy/Bl6W8Qp+dY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AAwo4WfgZzXHMIsr1VJvRqppUmLx29pTYqraz70xvDKGOKwqtPzJxu9x2f3pj42tC xl/0y4+5byyc5j253L4LqqisHaX3p6buJIiMg22NlUbXCoHfpYwAIMOUcnThpSRjjw tO1mmD4yC7EIeC5yRy7bwsIQOdxiygjbQof48MQ1MuhTBmjhESvsXdsg9/bl/KEbjq q4MIM3m9fGMCrRb+LAcO023kaWTumd5v9gxrwzZ7T2ITm7dHUco/DU0+EZXCe/ze3y uPfuEottAitQ4viQHFwJZmVhVn9TEnbo542D8vXxTcMwZ7dTgwXpbjYkDuyvmzP0Hc scPkHJ6yNiueQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BE06D69290; Sat, 10 Jan 2026 13:30:08 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id tzgAq3RBG_4X; Sat, 10 Jan 2026 13:30:08 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768077008; bh=shLy0er698rV3LEQwbJtTgrZT68j5UqDXoER31Gtoos=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=evVW+l2n1BHKxMqzlr74PPLoZVhIrgmZVWSXFPoEFlwloKhu6zXNKxq/qyjCUvKTf q3CujszWqS72G8yNj6h47+lOKOAjoZpHH9lwJlpaGNLJafwcZiMterivBDMxUrGKUz YQgNz9VN/x+/xLIJzQXeStIyVJQFRd/qgc8gTqlKBdXuJecEU6vRzVh7QcXPUERHEo hNf46mKYsIoHdY/84UveYlupalZuB3dYAf/fkLuuwuSTFWNl6Lhlp1QQvI5JrFX6ER npxQpt4HYIMJsekQVlLTcN2ENDDo6ylJyQVAT+eEqlbrQoTEeORwjOKmL/o1K+lZlY kyawh+KgZuACg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 0B7B26927E; Sat, 10 Jan 2026 13:30:07 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 10 Jan 2026 13:28:43 -0700 Message-ID: <20260110202906.187370-12-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260110202906.187370-1-sjg@u-boot.org> References: <20260110202906.187370-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: CFLW5TIROX45EWFQUMG4MUU5LVOMDIGE X-Message-ID-Hash: CFLW5TIROX45EWFQUMG4MUU5LVOMDIGE X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 11/26] boot: pxe: Add a helper to add to the file list List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add a helper function to add files to a label's file list. This makes it easier to add files. Refactor parse_fdtoverlays() to use the new helper, taking a label pointer instead of an alist pointer. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- boot/pxe_parse.c | 61 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/boot/pxe_parse.c b/boot/pxe_parse.c index b516da8f759..51fce1d5737 100644 --- a/boot/pxe_parse.c +++ b/boot/pxe_parse.c @@ -327,10 +327,37 @@ static bool has_fdtoverlays(struct alist *files) return false; } +/** + * label_add_file() - Add a file to a label's file list + * + * @label: Label to add file to + * @path: Path to file (will be duplicated) + * @type: Type of file (PFT_KERNEL, PFT_INITRD, etc.) + * Return: 0 on success, -ENOMEM on allocation failure + */ +static int label_add_file(struct pxe_label *label, const char *path, + enum pxe_file_type_t type) +{ + struct pxe_file item; + + item.path = strdup(path); + if (!item.path) + return -ENOMEM; + item.type = type; + item.addr = 0; + item.size = 0; + if (!alist_add(&label->files, item)) { + free(item.path); + return -ENOMEM; + } + + return 0; +} + /* - * Parse a space-separated list of overlay paths into an alist. + * Parse a space-separated list of overlay paths into a label's file list. */ -static int parse_fdtoverlays(char **c, struct alist *files) +static int parse_fdtoverlays(char **c, struct pxe_label *label) { char *val, *start; int err; @@ -341,7 +368,6 @@ static int parse_fdtoverlays(char **c, struct alist *files) start = val; while (*val) { - struct pxe_file item; char *end; /* Skip leading spaces */ @@ -351,23 +377,22 @@ static int parse_fdtoverlays(char **c, struct alist *files) if (!*val) break; - /* Find end of this path */ + /* Find end of this path and temporarily null-terminate */ end = strchr(val, ' '); - if (end) { - item.path = strndup(val, end - val); - val = end; - } else { - item.path = strdup(val); - val += strlen(val); - } - item.type = PFT_FDTOVERLAY; - item.addr = 0; - item.size = 0; + if (end) + *end = '\0'; - if (!item.path || !alist_add(files, item)) { - free(item.path); + err = label_add_file(label, val, PFT_FDTOVERLAY); + if (err) { free(start); - return -ENOMEM; + return err; + } + + if (end) { + *end = ' '; + val = end + 1; + } else { + break; } } @@ -605,7 +630,7 @@ static int parse_label(char **c, struct pxe_menu *cfg) break; case T_FDTOVERLAYS: if (!has_fdtoverlays(&label->files)) - err = parse_fdtoverlays(c, &label->files); + err = parse_fdtoverlays(c, label); break; case T_LOCALBOOT: label->localboot = 1;