From patchwork Fri Jan 9 23:11:21 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1408 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=1768000389; bh=kmiKst+/3ENQf/b1yOQVgt1qileuT+9vnb6nzUzjZaM=; 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=YFDoVgTxT5BRFQaVBxkBOCg1mAMH6/osS/jKmYJ2REc57sXnIyczJsE8JvCW2v8eE MazaH10CgLURvuBUu0Rqo2wPt34yQyFHii+2g9O/WhnUtsTD+mDuqhnA+MiFyVhIU8 jDJCAwiIhwML9kRJte2c54LX5dhKK93oi4+AM0W6XOsust4L0i00SJSjPKAz7ITxkN 3pMgPZ7bYI1LDpO1VwJATcaGddDAIN38eiulmt3GCaazbfxQ2pXkTCb8shg3lD9K6D Q4ESyOE6i3RAEK6/dFkElR7azMg2Z2hiwe1i2anvjQ6GdNC2SgW1DAmgu9syVLTDiL 6SVZZKrjrUaIA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4F74169241 for ; Fri, 9 Jan 2026 16:13:09 -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 xYIBfPinrtQu for ; Fri, 9 Jan 2026 16:13:09 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768000389; bh=kmiKst+/3ENQf/b1yOQVgt1qileuT+9vnb6nzUzjZaM=; 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=YFDoVgTxT5BRFQaVBxkBOCg1mAMH6/osS/jKmYJ2REc57sXnIyczJsE8JvCW2v8eE MazaH10CgLURvuBUu0Rqo2wPt34yQyFHii+2g9O/WhnUtsTD+mDuqhnA+MiFyVhIU8 jDJCAwiIhwML9kRJte2c54LX5dhKK93oi4+AM0W6XOsust4L0i00SJSjPKAz7ITxkN 3pMgPZ7bYI1LDpO1VwJATcaGddDAIN38eiulmt3GCaazbfxQ2pXkTCb8shg3lD9K6D Q4ESyOE6i3RAEK6/dFkElR7azMg2Z2hiwe1i2anvjQ6GdNC2SgW1DAmgu9syVLTDiL 6SVZZKrjrUaIA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3D17A69206 for ; Fri, 9 Jan 2026 16:13:09 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768000387; bh=1qOxjJ7DT9XboIxnXTfbwtqbzb1/5Dq/LbI9LGV0324=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JbmYmdG/ESlbdbygIYZ+IXnDXD9kn5Z/b6lCqaapQHuKK6YnSbSnpsQ939LvXeotS LubL7X7rSbqwUI76j7Yjr3M5xuBRUuKoCNUehhkq0ah0SAO0byBRu5mFNzBCBmdZKg iRhpJk52VLaFRNLomWI8rLmTMmvEoOQvuqAl01JsOeUptQjTMUWarULLw1jde7G4tU e3h7+y3G7kaQytCSFcHyTxJ+CkJcACsCUoBr4mSE/oBVMomNvYRaq6Uqz91dsICGJx xQD55XNlmuEiH7wsfIKwlc9lnHO7YSG9XN5+alopAXEphLLD9cPhOEsXeeS8mSq8MP AvYcojII4I4iQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 69ED169206; Fri, 9 Jan 2026 16:13:07 -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 70VJFrTtwCxy; Fri, 9 Jan 2026 16:13:07 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768000383; bh=f+O9/qvYHe5aBou6Jt7cTiB81XLv/7O99x2JZn5KXhQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j1MxINUkOQhaZUnGfT3M7dbpoFV/nLM7azNtMHK5GkS48trpLQosO1ulxavkK8XQH 7GoWvmXHIDE4oJjyf14s7RCOCqgKUcnloVH9igs5Hlk9RV2CvootSA3EUmqzBz7f3A opjXIVAw/IG+8EY+SxgdPSag9ZqIeTch49SWUmCcKlA+6SHbbj+CcJX/nOTL4OHg5K +ugUUt5A+f9uSoseqAefCqdXP0K31Cs5xf62xX8/nUGG6LDy4Fja+6I6oyUqM9cst6 Zl6sF9uYX9l3uZS/WjiQDO304qOwxLLr3Cu3Px9uaw55O3o13pFcxjSFKdyLgkNtHO 3FDSn9rXpDYBg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 0C07669235; Fri, 9 Jan 2026 16:13:02 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 9 Jan 2026 16:11:21 -0700 Message-ID: <20260109231151.4056804-13-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260109231151.4056804-1-sjg@u-boot.org> References: <20260109231151.4056804-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: KMQ237IYZDHZ2WGHD7VBPHUZRVSV36BO X-Message-ID-Hash: KMQ237IYZDHZ2WGHD7VBPHUZRVSV36BO 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 12/32] boot: pxe: Add pxe_menu_init() function 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 Extract the pxe_menu allocation and initialisation from parse_pxefile() into a new pxe_menu_init() function. This provides symmetry with pxe_menu_uninit() and allows callers to create a menu structure without going through the full parsing flow. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- boot/pxe_utils.c | 20 +++++++++++++++----- include/pxe_utils.h | 11 +++++++++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c index a824b1b5623..e0b7faddbd0 100644 --- a/boot/pxe_utils.c +++ b/boot/pxe_utils.c @@ -900,6 +900,20 @@ static int label_boot(struct pxe_context *ctx, struct pxe_label *label) return 1; } +struct pxe_menu *pxe_menu_init(void) +{ + struct pxe_menu *cfg; + + cfg = malloc(sizeof(struct pxe_menu)); + if (!cfg) + return NULL; + + memset(cfg, '\0', sizeof(struct pxe_menu)); + INIT_LIST_HEAD(&cfg->labels); + + return cfg; +} + void pxe_menu_uninit(struct pxe_menu *cfg) { struct list_head *pos, *n; @@ -924,14 +938,10 @@ struct pxe_menu *parse_pxefile(struct pxe_context *ctx, unsigned long menucfg) char *buf; int r; - cfg = malloc(sizeof(struct pxe_menu)); + cfg = pxe_menu_init(); if (!cfg) return NULL; - memset(cfg, 0, sizeof(struct pxe_menu)); - - INIT_LIST_HEAD(&cfg->labels); - buf = map_sysmem(menucfg, 0); r = parse_pxefile_top(ctx, buf, menucfg, cfg, 1); diff --git a/include/pxe_utils.h b/include/pxe_utils.h index 0de2f49aab5..0ea250300d6 100644 --- a/include/pxe_utils.h +++ b/include/pxe_utils.h @@ -179,11 +179,18 @@ struct pxe_context { }; /** - * pxe_menu_uninit() - Destroy an allocated pxe structure + * pxe_menu_init() - Allocate and initialise a pxe_menu structure + * + * Return: Allocated structure, or NULL on failure + */ +struct pxe_menu *pxe_menu_init(void); + +/** + * pxe_menu_uninit() - Free a pxe_menu structure * * Free the memory used by a pxe_menu and its labels * - * @cfg: Config to destroy, previous returned from parse_pxefile() + * @cfg: Config to free, previously returned from pxe_menu_init() */ void pxe_menu_uninit(struct pxe_menu *cfg);