From patchwork Sun Mar 22 23:57:10 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2044 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=1774223876; bh=cIxnS1E9sRHOdKdUsy79pDHrtgb5hr1Yg5to0Lr9pO4=; 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=lKcuheTuuWqRR54vhHgN1/LdkYhnug4JfCgCJdmmjMp54SYb1BbVGolkQTdq1Bpv8 N/GpanaSEEFr9ufb3AfMIsnbbpaZWNAsbXIP5uXS289KD5R8sE2NuDnT2eshZKYUBn V9/KYy4hJk/YRtdzW1KQNKvXdWzUGq4O2FyknCnlVsemxtwxRmPgEvpcV2an2Lzgzk jonRu86YdWMVi8z1kP+jjx6tK1ovGJUKmfHDuoQGb3cAUmGstaqR2YyPU7hHH/e8Jl NtEy97T8NCgbWAY2SDo1dMYu9kDi0p1XMx/05NdlHpgRCR1Nc2c4aqt8NdQQ6UFF8i xyxVrD+SaItAQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A0DD76A1E2 for ; Sun, 22 Mar 2026 17:57:56 -0600 (MDT) 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 xSULSvlpvl5S for ; Sun, 22 Mar 2026 17:57:56 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1774223873; bh=cIxnS1E9sRHOdKdUsy79pDHrtgb5hr1Yg5to0Lr9pO4=; 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=rlpVNfllp4bZbkvV/UakC51x+d0gtb/3jFZxSnYrREsEHGql0Df/zIQKaPkeAfUoO pX5XC02JYj/L8kaZ/EQwsymTsjMNyAjA5u+M0dMy2ulOjDMDA3woFoiiBEbZlUVg8X LZ+6cJYG8H6P6ATmbr21dQDxFvuQOP0VpX8P2RLs8usLzf6uo6MwjjFzt9i/JnZETh sJnYFAg5pQdm8U/AsO7WzeP8/mO9Ntuk74gUZilVPnJHj4zro+Umel98gUbjk/dNYk u9tq+pzCH9L6BhnBd71RbVmjxD83555P6zFmx4uiUoB4U0jpVusvPZDnwJ9e6+Zm5G hpdF6AXIJLZsw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 10D476A20B for ; Sun, 22 Mar 2026 17:57:53 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1774223871; bh=V5CJc5IPQNcbBKApmyZ1ZQlXAk7Huc/UnHg8Zu9MWyM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=liYfEse+ARwFcbkSDGp3fQEHkM0FW4DlMXXsZ0myVZu2fOyycRqeYVFxAQgVB2hlR GJJcIKvppPA55TPM0FJfoWJr6+UeBEdnFYRk5n953tyz7LfovLBUJcJjSxsKtOgovp JL8EfX6EORKpucs5Zx150Es5xteNJO+air7BxI77MF7gtsPHYFFYNGpe80Zqi3szVX AeUsGkZyg8ATg7eSTfIz0cxAmaJO2UE7MKuNaYWUbukahx3DCYYBwVJKW6O8aX4cA7 8NkBqsPl9BcVSkQ87nK8q2pr7SIpWf5vpWGiAZAUr4EYjR2j0rWwy4kIqvLVayabgX XkyYaJUU7Im9w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7E9076A204; Sun, 22 Mar 2026 17:57:51 -0600 (MDT) 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 Pvoyx_xvH6rq; Sun, 22 Mar 2026 17:57:51 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1774223866; bh=eIkHtwxQuY7Ofeh7vzilbJHMr+P8AnjbsFyIH4rt7J0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=peWpIt9Sl7IURkSNcV9HMsBuoUJoqfBb4mxtMZgVCch5fGjcuxlViyBB5YKmNEE2M wyHMI/3+nzvi+EH6eXzJaHjr7HC6GJ0ilLYPjh3JtoommjQcPLXuyLR1a+Swll8FwG Nmp/OR8zrwCUpo6/muGCwWziES3BHLipR07I8Nkv0CemrkAoc+AAWw+IXDleQd3KAp 8eC8J3+cPU70VlSBdTBY3eJahsCURzTHFfOtvPSUypuwVjUAnPUstpzX9QnZubc28b Rf32+PclCpGXRdSEIdXjlbMbgHI402Y9Xcmw9mbjxH/Q1JB2tYZY/IWKXRhW9cV/do R31CSlcWz45gA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id AB03D6A1E2; Sun, 22 Mar 2026 17:57:46 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Sun, 22 Mar 2026 17:57:10 -0600 Message-ID: <20260322235719.1729267-13-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260322235719.1729267-1-sjg@u-boot.org> References: <20260322235719.1729267-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: QHMW7O4N22VSP65JUKFFYQMPMSXJ2SGY X-Message-ID-Hash: QHMW7O4N22VSP65JUKFFYQMPMSXJ2SGY 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: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 12/14] extlinux: Add remove() to fix pxe_context leak 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 The extlinux and PXE drivers allocate a pxe_context in priv but never free it on device removal, leaking the bootdir string and any parsed menu. Add extlinux_bootmeth_remove() which frees the context, shared by both drivers. Move the VBE driver to use a pxe_context embedded in its own abrec_priv, since extlinux_plat no longer contains it. Signed-off-by: Simon Glass --- boot/bootmeth_extlinux.c | 12 ++++++++++++ boot/bootmeth_pxe.c | 1 + boot/vbe_abrec.h | 4 ++++ boot/vbe_abrec_os.c | 8 ++++---- include/extlinux.h | 10 ++++++++++ 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/boot/bootmeth_extlinux.c b/boot/bootmeth_extlinux.c index ad2f32ca8a5..ca9120c3f99 100644 --- a/boot/bootmeth_extlinux.c +++ b/boot/bootmeth_extlinux.c @@ -233,6 +233,17 @@ static int extlinux_local_read_all(struct udevice *dev, struct bootflow *bflow) } #endif +int extlinux_bootmeth_remove(struct udevice *dev) +{ + struct extlinux_priv *priv = dev_get_priv(dev); + + if (priv->ctx.cfg) + pxe_menu_uninit(priv->ctx.cfg); + pxe_destroy_ctx(&priv->ctx); + + return 0; +} + static int extlinux_bootmeth_bind(struct udevice *dev) { struct bootmeth_uc_plat *plat = dev_get_uclass_plat(dev); @@ -267,6 +278,7 @@ U_BOOT_DRIVER(bootmeth_1extlinux) = { .of_match = extlinux_bootmeth_ids, .ops = &extlinux_bootmeth_ops, .bind = extlinux_bootmeth_bind, + .remove = extlinux_bootmeth_remove, .plat_auto = sizeof(struct extlinux_plat), .priv_auto = sizeof(struct extlinux_priv), }; diff --git a/boot/bootmeth_pxe.c b/boot/bootmeth_pxe.c index 55e7f60c5cd..772acc9107d 100644 --- a/boot/bootmeth_pxe.c +++ b/boot/bootmeth_pxe.c @@ -193,6 +193,7 @@ U_BOOT_DRIVER(bootmeth_zpxe) = { .of_match = extlinux_bootmeth_pxe_ids, .ops = &extlinux_bootmeth_pxe_ops, .bind = extlinux_bootmeth_pxe_bind, + .remove = extlinux_bootmeth_remove, .plat_auto = sizeof(struct extlinux_plat), .priv_auto = sizeof(struct extlinux_priv), }; diff --git a/boot/vbe_abrec.h b/boot/vbe_abrec.h index 590ad3cfacb..005e64af25f 100644 --- a/boot/vbe_abrec.h +++ b/boot/vbe_abrec.h @@ -9,6 +9,8 @@ #ifndef __VBE_ABREC_H #define __VBE_ABREC_H +#include + #include #include @@ -34,6 +36,7 @@ struct udevice; * @version_size: Size of the version info * @storage: Storage device to use, in the form , e.g. "mmc1" * @oem_devicetree: true if we should read an OEM devicetree + * @ctx: PXE context for extlinux boot/read_all */ struct abrec_priv { u32 area_start; @@ -45,6 +48,7 @@ struct abrec_priv { u32 version_size; const char *storage; bool oem_devicetree; + struct pxe_context ctx; }; /** struct abrec_state - state information read from media diff --git a/boot/vbe_abrec_os.c b/boot/vbe_abrec_os.c index 7d5c9bc9dcb..9d0136b059b 100644 --- a/boot/vbe_abrec_os.c +++ b/boot/vbe_abrec_os.c @@ -204,7 +204,7 @@ err_buf: static int vbe_abrec_boot(struct udevice *dev, struct bootflow *bflow) { - struct extlinux_plat *plat = dev_get_plat(dev); + struct abrec_priv *priv = dev_get_priv(dev); const struct bootflow_img *img; int ret; @@ -231,16 +231,16 @@ static int vbe_abrec_boot(struct udevice *dev, struct bootflow *bflow) printf("Loading OS FIT%s\n", img ? " keeping existing FDT" : ""); - return extlinux_boot(dev, bflow, &plat->ctx, vbe_abrec_getfile, true, + return extlinux_boot(dev, bflow, &priv->ctx, vbe_abrec_getfile, true, bflow->fname, img); } #if CONFIG_IS_ENABLED(BOOTSTD_FULL) static int vbe_abrec_read_all(struct udevice *dev, struct bootflow *bflow) { - struct extlinux_plat *plat = dev_get_plat(dev); + struct abrec_priv *priv = dev_get_priv(dev); - return extlinux_read_all(dev, bflow, &plat->ctx, vbe_abrec_getfile, + return extlinux_read_all(dev, bflow, &priv->ctx, vbe_abrec_getfile, true, bflow->fname); } #endif diff --git a/include/extlinux.h b/include/extlinux.h index 66500f4c8cf..8630a8e3dc7 100644 --- a/include/extlinux.h +++ b/include/extlinux.h @@ -42,6 +42,16 @@ struct extlinux_priv { struct pxe_context ctx; }; +/** + * extlinux_bootmeth_remove() - Remove function for extlinux-based bootmeths + * + * Frees the PXE context. Shared by extlinux and PXE drivers. + * + * @dev: Bootmethod device + * Return: 0 if OK + */ +int extlinux_bootmeth_remove(struct udevice *dev); + /** * extlinux_set_property() - set an extlinux property *