From patchwork Mon Mar 16 18:30:24 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2012 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=1773685872; bh=PD+BNsVUw9sZRlwUaAswdNQm/QqEWOyFmETtLBoqxM8=; 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=U85gD+nVnt1TN7PuEkj8cDV+EyjvJL92oeLe79uWvc4uGqWf0/jrlrBaaUqDDqf3V 6Nzfg6FS59M8p7SY/sl1JZEZM24xXcCf8inueReKRdbS09v3IOiubqvJPi3nB5rTMh dXM2f916ruYaKZdiEck9qoHZ8do4mUS8gCaH76yzq0lNwCcy60EQ3fA1/T2Z1KU8E0 ues99hMptX13HE74CrXr5zU2Og5jyHJKfV2G6fSbw/s2XJ4scIuhiPLn2z978zXNr4 A2acEegj2ybaUXN4rLiJwkq23kcfQKptN+CpSJ8C/YbOpnCVvFIij4VhbLn7P3dNdY Ia2AYak6fPwwg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7CCAA6A0A5 for ; Mon, 16 Mar 2026 12:31:12 -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 uXFnXzCegjVh for ; Mon, 16 Mar 2026 12:31:12 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685872; bh=PD+BNsVUw9sZRlwUaAswdNQm/QqEWOyFmETtLBoqxM8=; 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=U85gD+nVnt1TN7PuEkj8cDV+EyjvJL92oeLe79uWvc4uGqWf0/jrlrBaaUqDDqf3V 6Nzfg6FS59M8p7SY/sl1JZEZM24xXcCf8inueReKRdbS09v3IOiubqvJPi3nB5rTMh dXM2f916ruYaKZdiEck9qoHZ8do4mUS8gCaH76yzq0lNwCcy60EQ3fA1/T2Z1KU8E0 ues99hMptX13HE74CrXr5zU2Og5jyHJKfV2G6fSbw/s2XJ4scIuhiPLn2z978zXNr4 A2acEegj2ybaUXN4rLiJwkq23kcfQKptN+CpSJ8C/YbOpnCVvFIij4VhbLn7P3dNdY Ia2AYak6fPwwg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 522EB6A09E for ; Mon, 16 Mar 2026 12:31:12 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685869; bh=yyvwhUYiZwCMoj6f4yT+dV8fYaICEocfunV4HiTvM1s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LKpWArP5zSaFfsuHk+vZ1obZHOtL3wBKdsKMOMDz9iS0tN7h06tSfAWaNtj3r++oH h6cQ+Fyx66s587RsaNtG3UcEcUiNaxSB9qoz0zwEMVfTnIV3m6z1gW9gaa5+vsHZpj kgOnX7eQhCr85G71pjr/RU2Dgm4NPs8ZObrrBplc0xolcHRed4xlVVXF9L78z25Jey VIBKuCyFjarLsRzeiyvSwL8p6UV/ErdPGm/qSAbyd97jmdDEbUGg6/EV1P9RdPJVG1 ZQV6A7Lr1sJgsGakgCRaV/tCdlDOKxS7BORZGlWG53BcB5grRHkSOwPUVKUG2IfXHw E2ULyab/dvm9g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 182CB6A07B; Mon, 16 Mar 2026 12:31:09 -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 vi7nBsC307YB; Mon, 16 Mar 2026 12:31:09 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685868; bh=FwcSQaTjr1zfT6Wkabax1GMesb4YuCCe0gMuQRbCsgg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S2WMnDUj2BPn3g4M22/QHTK/0nhzGD93DfHRKCfCeYW6iyZ736LzgTBAVeDpWX+AW rUm12pBcFlzuTOcG3wmjX5e5cINd4CBDIDzCCucdNtvS5DspjvRvsjXU5fEeiQRmbp 4LVU9SRBCAKon12TaFwNJpuRVXyFTOPcJ3F3FaoGsdts2yDPwufh0bnB1L/8fA5hfL Db1N7jgIt2rtPzPCiYzhxZvfvyWrYUSHoUJ0H1fSswEm/MEkoNyPNcrkttRWOJ2HjU UKf5UZ/xNfFKLEZG916P1ZM/xrovN/Cwq9qJahy8EPzT28fU3EEn16sNp91uuOThTc Io2XcGQRFyvXg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 5573C6A078; Mon, 16 Mar 2026 12:31:08 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 12:30:24 -0600 Message-ID: <20260316183050.3855921-2-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316183050.3855921-1-sjg@u-boot.org> References: <20260316183050.3855921-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: PWLVXUCZICJ6URAONLERCE2NOOLCHT5J X-Message-ID-Hash: PWLVXUCZICJ6URAONLERCE2NOOLCHT5J 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 01/17] kbuild: Use relative paths in generated .incbin directives 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 generated .S files for fonts, images, splash screens, signer binaries and EFI apps use .incbin with the full prerequisite path. When building with O= this bakes an absolute path into the .S file. If the build directory is later used on a different machine (e.g. in a container), the assembler cannot find the source file. Use $(src)/$(notdir $<) instead of $< so the .incbin directive contains a source-relative path like drivers/video/images/u_boot.bmp rather than an absolute one. Add -Wa,-I$(srctree) to the assembler flags so the assembler can resolve these paths. The DTB and DTBO rules are left unchanged since their prerequisites are generated files in the build directory. Signed-off-by: Simon Glass --- scripts/Makefile.lib | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index e2d0cb78bc9..8ccab5444cd 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -174,6 +174,7 @@ c_flags = -Wp,-MD,$(depfile) $(nostdinc) $(ubootinclude) \ $(basename_flags) $(modname_flags) a_flags = -Wp,-MD,$(depfile) $(nostdinc) $(ubootinclude) \ + -Wa,-I$(srctree) \ $(__a_flags) $(modkern_aflags) cpp_flags = -Wp,-MD,$(depfile) $(nostdinc) $(ubootinclude) \ @@ -494,7 +495,7 @@ cmd_S_ttf= \ echo '.balign 16'; \ echo '.global __ttf_$(*F)_begin'; \ echo '__ttf_$(*F)_begin:'; \ - echo '.incbin "$<" '; \ + echo '.incbin "$(src)/$(notdir $<)" '; \ echo '__ttf_$(*F)_end:'; \ echo '.global __ttf_$(*F)_end'; \ echo '.balign 16'; \ @@ -514,7 +515,7 @@ cmd_S_signer= \ echo '.balign 16'; \ echo '.global __signer_$(subst .,_,$(*F))_begin'; \ echo '__signer_$(subst .,_,$(*F))_begin:'; \ - echo '.incbin "$<" '; \ + echo '.incbin "$(src)/$(notdir $<)" '; \ echo '__signer_$(subst .,_,$(*F))_end:'; \ echo '.global __signer_$(subst .,_,$(*F))_end'; \ echo '.balign 16'; \ @@ -535,7 +536,7 @@ cmd_S_splash= \ echo '.balign 16'; \ echo '.global __splash_$(*F)_logo_begin'; \ echo '__splash_$(*F)_logo_begin:'; \ - echo '.incbin "$<" '; \ + echo '.incbin "$(src)/$(notdir $<)" '; \ echo '__splash_$(*F)_logo_end:'; \ echo '.global __splash_$(*F)_logo_end'; \ echo '.balign 16'; \ @@ -554,7 +555,7 @@ cmd_S_image= \ echo '.balign 16'; \ echo '.global __image_$(*F)_begin'; \ echo '__image_$(*F)_begin:'; \ - echo '.incbin "$<" '; \ + echo '.incbin "$(src)/$(notdir $<)" '; \ echo '__image_$(*F)_end:'; \ echo '.global __image_$(*F)_end'; \ echo '.balign 16'; \ @@ -594,7 +595,7 @@ cmd_S_efi= \ echo '.balign 16'; \ echo '.global __efi_$*_begin'; \ echo '__efi_$*_begin:'; \ - echo '.incbin "$<" '; \ + echo '.incbin "$(src)/$(notdir $<)" '; \ echo '__efi_$*_end:'; \ echo '.global __efi_$*_end'; \ echo '.balign 16'; \ From patchwork Mon Mar 16 18:30:25 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2014 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=1773685877; bh=xi91dwJ32XJ0gWhAfpoiK0gTJ0G+9wmhyR7Lnh9bP+0=; 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=m5fJ3bMDwsvOYl/TF92pzNLDEOlBjFQ1Swbb0y/nHsMBi2CdaHCCCt2BOPdKUAy+2 XjmC/0QLwWs8pgpgzlAVvTCyuOW98JBTp40LpS5sJGA+1bbPQVDnrAEENaJpSWnAJV bCECaVUoFyf4jjhKBFlI0QKpP/jWuvZ1spDbfIs8LKVIdg4yBDbDEnpzsYX0/mP6SZ 1jluPDv9T9OxRzWfEydaMfktxJq2fltV8Ad8TsCvf4H253VqpKI9xD5j0YYtCpICWr Ub0xYVXo28MO3td9dqFa2hYGaamZj96eHtO9J9LilMkcOdMg+1JYg1u8yFg+xeiO8j MmU543aFkmMwA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 56A656A09C for ; Mon, 16 Mar 2026 12:31:17 -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 WI_sc_Ea-pwr for ; Mon, 16 Mar 2026 12:31:17 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685875; bh=xi91dwJ32XJ0gWhAfpoiK0gTJ0G+9wmhyR7Lnh9bP+0=; 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=O7nQBqqV7fw+xIjq/257kIh5FpZwlkfvIEKSGohImw3MkQt7vRW9UaQpPNX4VZG/h jPcqpK0tEf7/pBGTi1qCVNPDJiIkAEuV3eu3Ydns8xgevoew6m2MQM69Hk/0UrMttO IUI29qsb9kQUt4QNqtQbf45spMGKEWLR3/mUbuhZ/x4KIWEYijFoLGYNJl2fQiQi+W bim3hATz6LuuQhfJcQnIS1obpe0klzeTS3B/qM5zW5dbghsVvxx1TTqozMj7OKoA5G Led+8E6MIECTlZZQWCKgVYPnBoI6L4kthhWeAGhk1vrbeVPPWomtEE0Z7WL2SW++KW ua1Vo6Ia95T6g== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B89796A078 for ; Mon, 16 Mar 2026 12:31:15 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685872; bh=sbvoOpgxWDS6+DtGi/B5BZvc1ITEiRgjIF35T1kVvd4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p4aIrQSDnvXMdwQl/fS4QnfIbwAKKsx9+G1Y6E+emmxWcmdj2H8084xrRhnhnZRLa fcK3Or9s2+KLyBqMZx1nlC5F7K5KW/qU8/6s7qdao9tR2Fz2mQX4QkAGcGNel3Vfhm 3ElV95pGShEFF8OtWWEBXOMj8KUsFdJhd5PBD3K0OwmAUJnTXV1X0VMNKmSz/u4hof QUghSlm01xCVBsRWeAzNp3cMkEYce7ppjuHOX/JjsO4CV2wkMmRYc+pIgcCAC0lQRw A1qPsKO5LWrgbH4ETssmHSWFcCG2ijmxiuWXp4kx0K12KctXuuC3wzbLWpdBAZ2UjC VRCMWCKhrJ/dw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 555F26A0A2; Mon, 16 Mar 2026 12:31:12 -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 lZqz75LJbo-U; Mon, 16 Mar 2026 12:31:12 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685869; bh=pSTLXkNLdW4vmR/BbNtuy+keBPNqI0E4rO0l5KqRRlU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lkqFtVl2C74OvS8r2MDdhaZNSejaKZ/6Hg5rDeHsOl94LqzrSdDDl3JUHFNn8lBgd cb9t3w3uh5Vh/EIy9bfy+uXUlt6F25DZnS0A5PovzuoE+lh5rKafzcLRSsnLArh4Io IyoTzcxHRotDh9r6SpK01LCFpHS5gu8bmwEtHthRmkGDk3GVw/0bUcnrNa6VnKq/C+ AdO4eOPKOH+6YCHqiRxQobFkR8luvuyTykiu/VUHjmzo3hHCFWEYjpgfs1/YyqYmtP q7tM9/AY+w8FPWlGsxglkigz3eERHdkMzpHZbC5cpjVFRIICkrCXzwjIzCCt1BPHPt MdDI/ykNxve7Q== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 57E9D6A078; Mon, 16 Mar 2026 12:31:09 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 12:30:25 -0600 Message-ID: <20260316183050.3855921-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316183050.3855921-1-sjg@u-boot.org> References: <20260316183050.3855921-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 437DP2EUV4DEFGVZFWPLCBK6YZ57FVRQ X-Message-ID-Hash: 437DP2EUV4DEFGVZFWPLCBK6YZ57FVRQ 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 02/17] blk: Return error from blk_get_devnum_by_uclass_idname() 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 blk_get_devnum_by_uclass_idname() returns a struct blk_desc pointer, discarding the error code from device_probe(). When probe fails due to out-of-memory or other errors, callers see NULL and report a generic 'device not found' instead of the actual cause. Change the function to return int and pass back the block device via a struct udevice ** parameter. This propagates the actual error from device_probe() through to callers. Rename the legacy version to blk_get_desc_by_uclass_idname() since it has no struct udevice to return, and use CONFIG_IS_ENABLED(BLK) in disk/part.c to select the right function. Signed-off-by: Simon Glass --- cmd/blkmap.c | 8 ++++---- disk/part.c | 23 ++++++++++++++++++----- drivers/block/blk-uclass.c | 19 +++++++++++-------- drivers/block/blk_legacy.c | 3 ++- include/blk.h | 24 +++++++++++++++++++----- test/boot/luks.c | 15 +++++++++------ 6 files changed, 63 insertions(+), 29 deletions(-) diff --git a/cmd/blkmap.c b/cmd/blkmap.c index 65edec899e2..2dc516e2ca4 100644 --- a/cmd/blkmap.c +++ b/cmd/blkmap.c @@ -28,7 +28,7 @@ struct map_handler { static int do_blkmap_map_linear(struct map_ctx *ctx, int argc, char *const argv[]) { - struct blk_desc *lbd; + struct udevice *ldev; int err, ldevnum; lbaint_t lblknr; @@ -38,15 +38,15 @@ static int do_blkmap_map_linear(struct map_ctx *ctx, int argc, ldevnum = dectoul(argv[2], NULL); lblknr = dectoul(argv[3], NULL); - lbd = blk_get_devnum_by_uclass_idname(argv[1], ldevnum); - if (!lbd) { + err = blk_get_devnum_by_uclass_idname(argv[1], ldevnum, &ldev); + if (err) { printf("Found no device matching \"%s %d\"\n", argv[1], ldevnum); return CMD_RET_FAILURE; } err = blkmap_map_linear(ctx->dev, ctx->blknr, ctx->blkcnt, - lbd->bdev, lblknr); + ldev, lblknr); if (err) { printf("Unable to map \"%s %d\" at block 0x" LBAF ": %d\n", argv[1], ldevnum, ctx->blknr, err); diff --git a/disk/part.c b/disk/part.c index b6dd3598c0f..d5ebdb037a6 100644 --- a/disk/part.c +++ b/disk/part.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -124,11 +125,23 @@ static struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart) if (!blk_enabled()) return NULL; - desc = blk_get_devnum_by_uclass_idname(ifname, dev); - if (!desc) { - debug("%s: No device for iface '%s', dev %d\n", __func__, - ifname, dev); - return NULL; + if (CONFIG_IS_ENABLED(BLK)) { + struct udevice *blk; + + ret = blk_get_devnum_by_uclass_idname(ifname, dev, &blk); + if (ret) { + log_debug("No device for iface '%s', dev %d: err=%d\n", + ifname, dev, ret); + return NULL; + } + desc = dev_get_uclass_plat(blk); + } else { + desc = blk_get_desc_by_uclass_idname(ifname, dev); + if (!desc) { + log_debug("No device for iface '%s', dev %d\n", + ifname, dev); + return NULL; + } } ret = blk_dselect_hwpart(desc, hwpart); if (ret) { diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c index a6ef34c2d5f..9c9169d6ac8 100644 --- a/drivers/block/blk-uclass.c +++ b/drivers/block/blk-uclass.c @@ -107,7 +107,8 @@ struct blk_desc *blk_get_devnum_by_uclass_id(enum uclass_id uclass_id, int devnu * name in a local table. This gives us an interface type which we can match * against the uclass of the block device's parent. */ -struct blk_desc *blk_get_devnum_by_uclass_idname(const char *uclass_idname, int devnum) +int blk_get_devnum_by_uclass_idname(const char *uclass_idname, int devnum, + struct udevice **blkp) { enum uclass_id uclass_id; enum uclass_id type; @@ -119,18 +120,18 @@ struct blk_desc *blk_get_devnum_by_uclass_idname(const char *uclass_idname, int if (type == UCLASS_INVALID) { debug("%s: Unknown interface type '%s'\n", __func__, uclass_idname); - return NULL; + return -ENODEV; } uclass_id = conv_uclass_id(type); if (uclass_id == UCLASS_INVALID) { debug("%s: Unknown uclass for interface type'\n", blk_get_uclass_name(type)); - return NULL; + return -ENODEV; } ret = uclass_get(UCLASS_BLK, &uc); if (ret) - return NULL; + return ret; uclass_foreach_dev(dev, uc) { struct blk_desc *desc = dev_get_uclass_plat(dev); @@ -146,15 +147,17 @@ struct blk_desc *blk_get_devnum_by_uclass_idname(const char *uclass_idname, int continue; } - if (device_probe(dev)) - return NULL; + ret = device_probe(dev); + if (ret) + return ret; debug("%s: Device desc %p\n", __func__, desc); - return desc; + *blkp = dev; + return 0; } debug("%s: No device found\n", __func__); - return NULL; + return -ENXIO; } /** diff --git a/drivers/block/blk_legacy.c b/drivers/block/blk_legacy.c index f36932183d1..28e40d23c71 100644 --- a/drivers/block/blk_legacy.c +++ b/drivers/block/blk_legacy.c @@ -199,7 +199,8 @@ int blk_dselect_hwpart(struct blk_desc *desc, int hwpart) return 0; } -struct blk_desc *blk_get_devnum_by_uclass_idname(const char *uclass_idname, int devnum) +struct blk_desc *blk_get_desc_by_uclass_idname(const char *uclass_idname, + int devnum) { struct blk_driver *drv = blk_driver_lookup_typename(uclass_idname); struct blk_desc *desc; diff --git a/include/blk.h b/include/blk.h index 877876cb622..14ab77f7c51 100644 --- a/include/blk.h +++ b/include/blk.h @@ -642,15 +642,29 @@ struct blk_desc *blk_get_devnum_by_uclass_id(enum uclass_id uclass_id, int devnu /** * blk_get_devnum_by_uclass_idname() - Get block device by type name and number * - * This looks up the block device type based on @uclass_idname, then calls - * blk_get_devnum_by_uclass_id(). + * This looks up the block device type based on @uclass_idname, then probes + * the device. + * + * @uclass_idname: Block device type name (e.g. "mmc") + * @devnum: Device number + * @blkp: Returns the block device + * Return: 0 if OK, -ENODEV if the uclass is not known, -ENXIO if the + * device is not found, or other -ve on probe error + */ +int blk_get_devnum_by_uclass_idname(const char *uclass_idname, int devnum, + struct udevice **blkp); + +/** + * blk_get_desc_by_uclass_idname() - Get block descriptor by type name/number + * + * Legacy version for non-DM block devices. * * @uclass_idname: Block device type name * @devnum: Device number - * Return: point to block device descriptor, or NULL if not found + * Return: pointer to block device descriptor, or NULL if not found */ -struct blk_desc *blk_get_devnum_by_uclass_idname(const char *uclass_idname, - int devnum); +struct blk_desc *blk_get_desc_by_uclass_idname(const char *uclass_idname, + int devnum); /** * blk_dselect_hwpart() - select a hardware partition diff --git a/test/boot/luks.c b/test/boot/luks.c index 339c7d7fc94..f6d0d951fee 100644 --- a/test/boot/luks.c +++ b/test/boot/luks.c @@ -220,6 +220,7 @@ BOOTSTD_TEST(bootstd_test_luks2_info, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); static int bootstd_test_luks_unlock(struct unit_test_state *uts) { struct blk_desc *desc; + struct udevice *blk; struct udevice *mmc; loff_t file_size; @@ -242,8 +243,8 @@ static int bootstd_test_luks_unlock(struct unit_test_state *uts) ut_assert_console_end(); /* Verify that a file can be read from the decrypted filesystem */ - desc = blk_get_devnum_by_uclass_idname("blkmap", 0); - ut_assertnonnull(desc); + ut_assertok(blk_get_devnum_by_uclass_idname("blkmap", 0, &blk)); + desc = dev_get_uclass_plat(blk); ut_assertok(fs_set_blk_dev_with_part(desc, 0)); ut_assertok(fs_size("/bin/bash", &file_size)); @@ -262,6 +263,7 @@ static int bootstd_test_luks2_unlock(struct unit_test_state *uts) { struct disk_partition info; struct blk_desc *desc; + struct udevice *blk; struct udevice *mmc; u8 master_key[512]; loff_t file_size; @@ -284,8 +286,8 @@ static int bootstd_test_luks2_unlock(struct unit_test_state *uts) ut_assert_console_end(); /* Verify that a file can be read from the decrypted filesystem */ - desc = blk_get_devnum_by_uclass_idname("blkmap", 0); - ut_assertnonnull(desc); + ut_assertok(blk_get_devnum_by_uclass_idname("blkmap", 0, &blk)); + desc = dev_get_uclass_plat(blk); ut_assertok(fs_set_blk_dev_with_part(desc, 0)); ut_assertok(fs_size("/bin/bash", &file_size)); @@ -312,6 +314,7 @@ static int setup_mmc14(struct unit_test_state *uts, struct udevice **mmcp) static int bootstd_test_luks2_unlock_prederived(struct unit_test_state *uts) { struct blk_desc *desc; + struct udevice *blk; struct udevice *mmc; loff_t file_size; @@ -333,8 +336,8 @@ static int bootstd_test_luks2_unlock_prederived(struct unit_test_state *uts) ut_assert_console_end(); /* Verify that a file can be read from the decrypted filesystem */ - desc = blk_get_devnum_by_uclass_idname("blkmap", 0); - ut_assertnonnull(desc); + ut_assertok(blk_get_devnum_by_uclass_idname("blkmap", 0, &blk)); + desc = dev_get_uclass_plat(blk); ut_assertok(fs_set_blk_dev_with_part(desc, 0)); ut_assertok(fs_size("/bin/bash", &file_size)); From patchwork Mon Mar 16 18:30:26 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2013 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=1773685874; bh=Gm0CzT+zx36Pyr2HB20Tt59bMjICL1I+CXfO5x1lQ3o=; 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=jjpCe/cLfarTTE/Hnn/eFE+aycb6obZ/SWFDa1HXrv2PdQmXgF4DMpWGbr7k57Xkm fcIjnEGRFbr9DS4mveV2vZ6XFcDMjguyt2+39OOjEFTD+kcQVRtsnFdEgqZixWh+1S sVlGCmCOIRZ1icrR2eztZdCkUTev1A5BXo0ysCarqPRM/i5ZmoOQ+uh8oUQg9HKeri bVoDwjWTXLTeMgHerDyQJDi30HiVP7jb6cI6+AkiKVaHitdUhYRWlxke0cJtugHYUW GWlBgReVD5jANjPZEoyMjUsTOxk0cDxhtX3aPuTd1fXYjeMtyG95yVTYqLGNDlJu/t wsrSfhOfIPYuA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DD03C6A078 for ; Mon, 16 Mar 2026 12:31:14 -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 P9Ml0BAUOHGT for ; Mon, 16 Mar 2026 12:31:14 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685874; bh=Gm0CzT+zx36Pyr2HB20Tt59bMjICL1I+CXfO5x1lQ3o=; 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=jjpCe/cLfarTTE/Hnn/eFE+aycb6obZ/SWFDa1HXrv2PdQmXgF4DMpWGbr7k57Xkm fcIjnEGRFbr9DS4mveV2vZ6XFcDMjguyt2+39OOjEFTD+kcQVRtsnFdEgqZixWh+1S sVlGCmCOIRZ1icrR2eztZdCkUTev1A5BXo0ysCarqPRM/i5ZmoOQ+uh8oUQg9HKeri bVoDwjWTXLTeMgHerDyQJDi30HiVP7jb6cI6+AkiKVaHitdUhYRWlxke0cJtugHYUW GWlBgReVD5jANjPZEoyMjUsTOxk0cDxhtX3aPuTd1fXYjeMtyG95yVTYqLGNDlJu/t wsrSfhOfIPYuA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C9C446A07B for ; Mon, 16 Mar 2026 12:31:14 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685872; bh=5fZh4pUBa+Q2ViQ2iuTCTQqXLjLbAuXNyez8i0I+YlA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PpCGe/GAjatH4iv6pk8aIUWmpOelKnsar7otCzxxy9f8iWIOX/82GJPDwdUcueWUB s6Z5/Zi62/aZiLZLmCzmP+HfVVdoss01QTxHemIvk2hblrMnq0PihjW3XXyGKGyLz1 rxDV8cJi3YS0efPeMjpyn87jNLfk9CRQ27oZxsMzHE+Oox/ggT/5U5AabDMEezaqDn enSern9NvudmsrlTc6cIQwuQqMJg9fWllxbreQm26E1wnctW08SY6K0O3kY4s8jP0v Bzc7N7sXswOA1LQbrkEiOSt3qJPfH8sDrGjoNZXeMcyh6XE7kKcZh7hct7pouX43LZ SoBIuyfBD1jTw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 52A246A09F; Mon, 16 Mar 2026 12:31:12 -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 VbQZIySNXl_e; Mon, 16 Mar 2026 12:31:12 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685870; bh=TsDjYSkRfxV9BtS/t/KGBmq9AdKfo8lYoPC5dcVjq40=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dE4dzYxkdYiItmMx8r2ZBIz2vQrAXoDF9Ldip47alXNDto/L5XhiSpEDlM8NSMfmK yAdCUiCxB/Q4Xbo8RkEuwr2Xk4DkVsOFFTJW9BmjQMrIusfOc5mFBWWbliDEx0eWKW kJXNz8340RI2D9ND1WHE+HPVcSnKaMO5bF5C40pBudwskkskWIAy6tmE1pQ94Ot4sa NfXEt3pJyXi2uZUhe2q/VxhHcLglN69mWNXJKdpFUUeO51WgmKMqLSLyN2ycQQ8ceg XB6xBryj9/QqFMsgDKVP6yUcBkrX7cPQJDtBAh+/ZuLzD6KtJyWmaxF4IIgH09jWe4 TtXReMsMS4p4A== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 73A816A07B; Mon, 16 Mar 2026 12:31:10 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 12:30:26 -0600 Message-ID: <20260316183050.3855921-4-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316183050.3855921-1-sjg@u-boot.org> References: <20260316183050.3855921-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: ZSGDDYPV5PU5EI3VB4IQDE2IIIDVTXTK X-Message-ID-Hash: ZSGDDYPV5PU5EI3VB4IQDE2IIIDVTXTK 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 03/17] sandbox: Return -ENOMEM when os_map_file() fails 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 os_map_file() returns -EPERM for all mmap() failures regardless of the actual errno. When mmap() fails with ENOMEM, return -ENOMEM so that callers can distinguish out-of-memory from other errors. Signed-off-by: Simon Glass --- arch/sandbox/cpu/os.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 142b685e031..c1381775b1b 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -299,7 +299,7 @@ int os_map_file(const char *pathname, int os_flags, void **bufp, int *sizep) ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, ifd, 0); if (ptr == MAP_FAILED) { printf("Can't map file '%s': %s\n", pathname, strerror(errno)); - ret = -EPERM; + ret = errno == ENOMEM ? -ENOMEM : -EPERM; goto out; } From patchwork Mon Mar 16 18:30:27 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2015 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=1773685877; bh=fVNmMixBAhygIufPlKImmrp0YXs80O6C9TlRUaVRFAs=; 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=XLXkMXkFTaeczTjY/m1iejSQxtmBAr+ogjn/QrMN9kkG7B0Y45reV+vl78n+2glF3 UQkwWjPW4g9y4dcaX7/MZ6ASe28SPLgyLkQuSg3LylOcp0rPux4X+nOqyFTtnJvEq7 1aUyf5bg+tOpSCGs1SLMoAPb7KNypN2kSf3ZDHQIO7p3lGqozFwO8Z6+wDjiNEC0WX 1trYnHhvRko71+0+Do3kmpzAQT3P7Eyx2X1oz63P+54gNYvR7svhv0TjIKfh7RaNsD /ywGU/wCKcql3OWK3+J2ptzr80gA1AOqvP2fkF4ORxnDmVTXUAc8xyRVkK3VTOq2IA hPLFzmrWk23nQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C2B276A0AB for ; Mon, 16 Mar 2026 12:31:17 -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 Dy6xScVbAW_t for ; Mon, 16 Mar 2026 12:31:17 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685876; bh=fVNmMixBAhygIufPlKImmrp0YXs80O6C9TlRUaVRFAs=; 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=Phi+Pz8tqPfXP41rNV6VbrTXdSuJyEUaCDBRZbxzHcpWT6RDiXNSJ9R6yLmhkOHuX o02iFxZ/IaNWOWe5mcFoum23l/MkBDEyCKgwm0gRfIijEwK7ukBaoFpBoXHVT80jJ5 jmwu6F4E6vXi354wNCJJmy/rvWUBjtzVJ9lFNwY8K5F2E+ALtKwQjgd3RdTJ4DCqy6 qP0dQFLwiFmcioFO3TOeUwg/yrFqZMoCeo+FF/G54Uz1kPLPYOJq/7LF4MxsV3XT5Z vz5Z6HM2BNWKnrsULD6c72UcixjVwdgMhZ50lB1rbhHba31Rm8OSc2xVVegXR+ZmKk Ki6R7o96/Jc0g== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7E4176A0AC for ; Mon, 16 Mar 2026 12:31:16 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685872; bh=JpPuuj/5BrLctW18NGU1yEBDFfuYHiLGEXwJ4bWHgYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UoeYAJNzI1szWMhZPuWNys55ZbVOO8OaEUMuryTik/ycEDf3MSBwI4AKAZ2wNcHxK XDy+LPvZX8GVtM2UennlmnK+EufEyDV7hcKmYeoEiJnHgUIeaWCjVEBGTqLK7m439+ /7chssCKdgfsqzc4JL0CLFen7aqFnrCw+dcN0SxQKp7ybVak3Wuz6L7eB26ljKkTb9 VXPQx1TpZL2aN3AP9mQpcnKfhfJD53oDdelm2CkePgZtW8rqD/bTyzV9oDDAh8P0K0 fYV6VEA/yWh43X+RL16huCPU0meEoLgi6ST7zvbfUMZE1GE2sgfdq87YjxrMuYyzv6 7+bAGZp21Hs3g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 67E516A07B; Mon, 16 Mar 2026 12:31:12 -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 tVAVVUxMmWvC; Mon, 16 Mar 2026 12:31:12 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685871; bh=qLO6P5qIq3ggthvDHRPGDmpsI8vNcJVipGwiKU4vRYA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p2FY/kUxkdDIeW7WqdaW82ymB38iIPaEhu1PKgEQdjs+aNdFUEjgHST4ILzOg2UtJ za/OVawTrzHE9xq7oFhu2/FdbKbNstlCLWLSiRJcZYEYRPN5vkxoDwtFlcdCT8Xfg/ UreZh1Ahi7lV4/gHVNuu5/JoSqe4xYl5w2EDi/idS51OW2aV/IJMUw96AMPtOE8QFN Z8G9hQF5+PUsEoQ63B4uTCOK8VuyArEvB7Sustca1jNRWkKqYfvyRj/QEDGgg4hYYO PVYDpGMMkz/q0r1kHe+LxHQf4s2p8QXUD1Bx53MNttLH24lUs9Mo8DMTC3reF8g1Q3 ZDMR+2jggcLyA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 32B8E6A081; Mon, 16 Mar 2026 12:31:11 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 12:30:27 -0600 Message-ID: <20260316183050.3855921-5-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316183050.3855921-1-sjg@u-boot.org> References: <20260316183050.3855921-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: QRPA4HMM6YMUPXDCG564TSYHRYBLDBOA X-Message-ID-Hash: QRPA4HMM6YMUPXDCG564TSYHRYBLDBOA 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 04/17] vbe: Propagate probe errors from vbe_get_blk() 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 vbe_get_blk() uses the updated blk_get_devnum_by_uclass_idname() which now returns the actual error from device_probe(). This replaces the generic -ENXIO that was returned when the block device could not be found, making out-of-memory and other probe failures visible to the caller. Signed-off-by: Simon Glass --- boot/vbe_common.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/boot/vbe_common.c b/boot/vbe_common.c index f9368a6a9ab..dbbbac3e96a 100644 --- a/boot/vbe_common.c +++ b/boot/vbe_common.c @@ -23,10 +23,11 @@ binman_sym_declare(ulong, u_boot_spl_bss_pad, size); int vbe_get_blk(const char *storage, struct udevice **blkp) { - struct blk_desc *desc; + struct udevice *blk; char devname[16]; const char *end; int devnum; + int ret; /* First figure out the block device */ log_debug("storage=%s\n", storage); @@ -38,10 +39,10 @@ int vbe_get_blk(const char *storage, struct udevice **blkp) strlcpy(devname, storage, end - storage + 1); log_debug("dev=%s, %x\n", devname, devnum); - desc = blk_get_dev(devname, devnum); - if (!desc) - return log_msg_ret("get", -ENXIO); - *blkp = desc->bdev; + ret = blk_get_devnum_by_uclass_idname(devname, devnum, &blk); + if (ret) + return log_msg_ret("get", ret); + *blkp = blk; return 0; } From patchwork Mon Mar 16 18:30:28 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2016 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=1773685882; bh=9CSJK53+W/KrXlf1JtqHlRy1vj7Y75kv0aG4hjEs/To=; 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=kDyxTP4mDkFBdp1N+dS6JjSKmlPyFKLjc7qNzmSVt2N0iyp3zUkvvIpSoHjFkLrRQ NRK/TK73jPXEVHM0YzNZTTYwau0rJiOITEznyl5AFZWH8z70eorZ3x492KHs0wklCR Fl2mDrqaXzG9DBBTgokFvqGh0k9HROaGoLVZHqL1FJW1vX3ksmt3KZwL9Fzl7Fl/L3 p/WQDV1UxT2rBURkr27kdVypZlA9T/pPraSj8oG46hNOfHUw9YytJDwphRNrvWeVd+ +5L2jgv3U61IA4emQLEwEj5bhdTQ30yNtPkObbjn8Ot9ECGXWtdcg2lUubbayNPLXR x2HXHyKXxKRzQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A6B3F6A078 for ; Mon, 16 Mar 2026 12:31:22 -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 aB66XKc3H-PW for ; Mon, 16 Mar 2026 12:31:22 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685882; bh=9CSJK53+W/KrXlf1JtqHlRy1vj7Y75kv0aG4hjEs/To=; 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=kDyxTP4mDkFBdp1N+dS6JjSKmlPyFKLjc7qNzmSVt2N0iyp3zUkvvIpSoHjFkLrRQ NRK/TK73jPXEVHM0YzNZTTYwau0rJiOITEznyl5AFZWH8z70eorZ3x492KHs0wklCR Fl2mDrqaXzG9DBBTgokFvqGh0k9HROaGoLVZHqL1FJW1vX3ksmt3KZwL9Fzl7Fl/L3 p/WQDV1UxT2rBURkr27kdVypZlA9T/pPraSj8oG46hNOfHUw9YytJDwphRNrvWeVd+ +5L2jgv3U61IA4emQLEwEj5bhdTQ30yNtPkObbjn8Ot9ECGXWtdcg2lUubbayNPLXR x2HXHyKXxKRzQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0118E6A08D for ; Mon, 16 Mar 2026 12:31:22 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685880; bh=kcbNo135hI/RXnGRhCHYhRbbyEs+aZJR+7r7YHqLq7A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VGtGKk2SykvJhwaeSqxkVAGo2zpnPtjxUQdRdIFDiccemIP9KtylHvG7i2mSED9nq l+sr8EiyvP6W2mM6Ycj5OwWI8trO1NZOXfomcclmAV1Pg3a1AFyx1LhRaPzUKg8C8K N8qpVUZserAuTEwxdP4elbq5yVwszHndTQeyGCjni36rChrNnxALaQr6hwkv1hx2jB oi4aKHMnxJ5ceNZPYZrkpQEunhJOS+3zuq2WyKgrrPL2524isYEk6F/CT0KvVbYaig GKc5pJ5eaOwUu+Mug/weAThDl/5y03g09tfdqLxNEMpgfwmKSGdWPCja3bc7K8bWkf Jc74EnXdklCuw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4DBA56A088; Mon, 16 Mar 2026 12:31:20 -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 it7hoYaP-Te4; Mon, 16 Mar 2026 12:31:20 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685872; bh=EZdE14Awo/4AMuaTQau4tOJ+G1T/XPtDcS2CzkA3Uhw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YJCpGeKqUL4xDb0hyrNOKK6CUoJBvagxngNLRnlq5vcRI0YqFIa2ZohB/lWDl4ZG4 cI2RVu5z0962MfrrtW9VQadu8qwP/MwBx67HlstgikRkWcG0MgjaYePci5TDqxn/zM nMhzicXWkDgOPcZVYO+oReoHhh+TgJ6CIbE/iy6lCkPn2VVresi6+AwDIjygMemyLO h389fAStvdqbH2e7jFkk6V2ZnlQEPVVJH8adULr+X15srNqEEuik/6NvqbvHs/S6xZ Lc2ZEAGfkpJ8CdXXaqter1VGxdEV8pq+9NCCE8v38RVrewqi2d3jB8p8BMNJ3lDr3K XS2HM/7v22G/w== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 131226A09B; Mon, 16 Mar 2026 12:31:12 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 12:30:28 -0600 Message-ID: <20260316183050.3855921-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316183050.3855921-1-sjg@u-boot.org> References: <20260316183050.3855921-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: BT43ILK5UCTQZPIOODPAFCII2CZMJMOG X-Message-ID-Hash: BT43ILK5UCTQZPIOODPAFCII2CZMJMOG 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 05/17] malloc: Add heap-snapshot leak-checking functions 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 malloc_leak_check_start(), malloc_leak_check_end(), malloc_leak_check_count() and malloc_leak_check_free() which take a snapshot of every in-use heap chunk and later report any new allocations with their address, size and caller backtrace. The snapshot is stored using os_malloc() so it does not perturb the heap being measured. Signed-off-by: Simon Glass --- common/dlmalloc.c | 230 ++++++++++++++++++++++++++++++++++++++++++++++ include/malloc.h | 81 ++++++++++++++++ 2 files changed, 311 insertions(+) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index 2bc5f63c0a8..e61f565bbab 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -7634,7 +7634,237 @@ int malloc_dump_to_file(const char *fname) return 0; } +#endif /* IS_ENABLED(CONFIG_SANDBOX) */ + +/** + * count_used_chunks() - Count the number of in-use heap chunks + * + * Walk the entire dlmalloc heap and count chunks that are currently in use. + * + * Return: number of used chunks + */ +static int count_used_chunks(void) +{ + mchunkptr q; + msegmentptr s; + int count = 0; + + if (!is_initialized(gm)) + return 0; + + for (s = &gm->seg; s; s = s->next) { + q = align_as_chunk(s->base); + while (segment_holds(s, q) && + q != gm->top && q->head != FENCEPOST_HEAD) { + if (is_inuse(q)) + count++; + q = next_chunk(q); + } + } + + return count; +} + +size_t malloc_mcheck_hdr_size(void) +{ +#if CONFIG_IS_ENABLED(MCHECK_HEAP_PROTECTION) + return sizeof(struct mcheck_hdr); +#else + return 0; +#endif +} + +size_t malloc_chunk_size(void *ptr) +{ + void *mem; + mchunkptr p; + + mem = (char *)ptr - malloc_mcheck_hdr_size(); + p = mem2chunk(mem); + + return chunksize(p); +} + +int malloc_leak_check_start(struct malloc_leak_snap *snap) +{ + mchunkptr q; + msegmentptr s; + int i; + + if (!is_initialized(gm)) + return -ENOENT; + + snap->count = count_used_chunks(); + + /* + * On sandbox, allocate from the host OS so the snapshot does not + * disturb the U-Boot heap. On other platforms, use the heap itself + * but reserve one extra slot for the snapshot's own chunk. + */ +#if IS_ENABLED(CONFIG_SANDBOX) + snap->addr = os_malloc(snap->count * sizeof(ulong)); +#else + snap->addr = malloc((snap->count + 1) * sizeof(ulong)); #endif + if (!snap->addr) + return -ENOMEM; + + i = 0; + for (s = &gm->seg; s; s = s->next) { + q = align_as_chunk(s->base); + while (segment_holds(s, q) && + q != gm->top && q->head != FENCEPOST_HEAD) { + if (is_inuse(q)) + snap->addr[i++] = (ulong)chunk2mem(q); + q = next_chunk(q); + } + } + snap->count = i; + + return 0; +} + +/** + * snap_has_addr() - Check whether an address is in the snapshot + * + * The addresses are stored in ascending heap order, so use binary search. + * + * @snap: Snapshot taken earlier + * @addr: Address to look for + * Return: true if found + */ +static bool snap_has_addr(struct malloc_leak_snap *snap, ulong addr) +{ + int lo = 0, hi = snap->count - 1; + + while (lo <= hi) { + int mid = lo + (hi - lo) / 2; + + if (snap->addr[mid] == addr) + return true; + if (snap->addr[mid] < addr) + lo = mid + 1; + else + hi = mid - 1; + } + + return false; +} + +/** + * count_new_allocs() - Count heap allocations not present in the snapshot + * + * @snap: Snapshot taken earlier + * Return: number of new allocations found + */ +static int count_new_allocs(struct malloc_leak_snap *snap) +{ + msegmentptr s; + int leaks = 0; + mchunkptr q; + + for (s = &gm->seg; s; s = s->next) { + q = align_as_chunk(s->base); + while (segment_holds(s, q) && + q != gm->top && q->head != FENCEPOST_HEAD) { + if (is_inuse(q) && + !snap_has_addr(snap, (ulong)chunk2mem(q))) + leaks++; + q = next_chunk(q); + } + } + + return leaks; +} + +/** + * print_new_allocs() - Print heap allocations not present in the snapshot + * + * @snap: Snapshot taken earlier + */ +static void print_new_allocs(struct malloc_leak_snap *snap) +{ + msegmentptr s; + mchunkptr q; + + for (s = &gm->seg; s; s = s->next) { + q = align_as_chunk(s->base); + while (segment_holds(s, q) && + q != gm->top && q->head != FENCEPOST_HEAD) { + if (is_inuse(q) && + !snap_has_addr(snap, (ulong)chunk2mem(q))) { + const char *caller = ""; + void *mem = chunk2mem(q); + size_t sz = chunksize(q); + +#if CONFIG_IS_ENABLED(MCHECK_HEAP_PROTECTION) + /* + * Read the caller directly from the mcheck + * header at the start of the chunk rather + * than searching the registry, which may + * have overflowed. Validate the canary first + * to avoid printing garbage from chunks + * allocated without mcheck (e.g. when mcheck + * was temporarily disabled). + */ + struct mcheck_hdr *hdr = mem; + int j; + + for (j = 0; j < CANARY_DEPTH; j++) + if (hdr->canary.elems[j] != MAGICWORD) + break; + if (j == CANARY_DEPTH && hdr->caller[0]) + caller = hdr->caller; +#endif + printf(" %lx %zx %s\n", (ulong)mem, sz, + caller); + } + q = next_chunk(q); + } + } +} + +int malloc_leak_check_end(struct malloc_leak_snap *snap) +{ + int leaks; + + if (!is_initialized(gm) || !snap->addr) + return -ENOENT; + + leaks = count_new_allocs(snap); + if (leaks) + print_new_allocs(snap); + + +#if IS_ENABLED(CONFIG_SANDBOX) + os_free(snap->addr); +#else + free(snap->addr); +#endif + snap->addr = NULL; + snap->count = 0; + + return leaks; +} + +int malloc_leak_check_count(struct malloc_leak_snap *snap) +{ + if (!is_initialized(gm) || !snap->addr) + return -ENOENT; + + return count_new_allocs(snap); +} + +void malloc_leak_check_free(struct malloc_leak_snap *snap) +{ +#if IS_ENABLED(CONFIG_SANDBOX) + os_free(snap->addr); +#else + free(snap->addr); +#endif + snap->addr = NULL; + snap->count = 0; +} int initf_malloc(void) { diff --git a/include/malloc.h b/include/malloc.h index 610289f3a6c..ded5520ca23 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -146,6 +146,21 @@ struct mallinfo { #endif /* HAVE_USR_INCLUDE_MALLOC_H */ #endif /* !NO_MALLINFO */ +/** + * struct malloc_leak_snap - Snapshot of heap allocations for leak checking + * + * Used by malloc_leak_check_start/end to record the set of in-use chunk + * addresses before a test, so that new (leaked) allocations can be identified + * afterwards. + * + * @addr: Array of chunk addresses + * @count: Number of entries in @addr + */ +struct malloc_leak_snap { + unsigned long *addr; + int count; +}; + /* malloc(size_t n) Returns a pointer to a newly allocated chunk of at least n bytes, or @@ -818,6 +833,72 @@ void malloc_backtrace_skip(bool skip); static inline void malloc_backtrace_skip(bool skip) {} #endif +/** + * malloc_chunk_size() - Return the dlmalloc chunk size for an allocation + * + * Given a pointer returned by malloc(), return the size of the underlying + * dlmalloc chunk. This is the size shown in heap dumps and leak reports. + * + * @ptr: Pointer returned by malloc/calloc/realloc + * Return: chunk size in bytes + */ +size_t malloc_chunk_size(void *ptr); + +/** + * malloc_mcheck_hdr_size() - Return the size of the mcheck header + * + * When CONFIG_MCHECK_HEAP_PROTECTION is enabled, each allocation has a + * header placed before the returned pointer. This returns its size, or + * 0 when mcheck is disabled. This is useful for computing the chunk + * address from a malloc pointer (chunk_addr = ptr - hdr_size). + * + * Return: size of struct mcheck_hdr, or 0 + */ +size_t malloc_mcheck_hdr_size(void); + +/** + * malloc_leak_check_start() - Record current heap allocations + * + * Walk the heap and save the address of every in-use chunk. This snapshot + * is later compared by malloc_leak_check_end() to find new allocations. + * Storage is allocated with os_malloc() so it does not perturb the heap. + * + * @snap: Snapshot structure to fill in + * Return: 0 on success, -ENOENT if heap not initialised, -ENOMEM on failure + */ +int malloc_leak_check_start(struct malloc_leak_snap *snap); + +/** + * malloc_leak_check_end() - Report allocations not present in the snapshot + * + * Walk the heap and print every in-use chunk whose address was not recorded + * in the snapshot taken by malloc_leak_check_start(). Each leaked allocation + * is printed with its address, size, and caller (when mcheck is enabled). + * Frees the snapshot storage afterwards. + * + * @snap: Snapshot taken earlier with malloc_leak_check_start() + * Return: number of leaked allocations, or -ve on error + */ +int malloc_leak_check_end(struct malloc_leak_snap *snap); + +/** + * malloc_leak_check_count() - Count allocations not present in the snapshot + * + * Like malloc_leak_check_end() but only counts, without printing or freeing + * the snapshot. + * + * @snap: Snapshot taken earlier with malloc_leak_check_start() + * Return: number of leaked allocations, or -ve on error + */ +int malloc_leak_check_count(struct malloc_leak_snap *snap); + +/** + * malloc_leak_check_free() - Free a snapshot without checking + * + * @snap: Snapshot taken earlier with malloc_leak_check_start() + */ +void malloc_leak_check_free(struct malloc_leak_snap *snap); + /** * mem_malloc_init() - Initialize the malloc() heap * From patchwork Mon Mar 16 18:30:29 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2017 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=1773685886; bh=FbodRPITxWBrOtuufPy3Z6qimg7890iTtZ1cXcmoh4Q=; 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=rKDm+tCO6GHIzXU8q1U2/jK4Tlb1wOO3Hm50lLVrSunOZx2JYy16UuoUKid1NB/sy HZ3OFwRQHhlIrVuDFyB/IuHw+8uhYC36FNmzsBUj0ZsapRq7MPXKEev8bJsCtfwIRe hpt9CmxkjViXppkYxq4fSQHoh67EvcAKmwOLFLOwnnCRY9ejj0mNAgMyohXwZxE3i5 1R76rGNY5gYbCPEzr2lcacE1whqfdkMUUdzaEkYWDVGZVJBvtz67dJXbIuR8h8ZC5X N+vKAcXZ/YnJcJUA91hAlu2XLwhgwXNUGtq6PCe78DdJBKWhl/lYKrRyOBcHin0DAm FKFN/z1exvEFg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 841BA6A0A9 for ; Mon, 16 Mar 2026 12:31:26 -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 OqWfY9giIch5 for ; Mon, 16 Mar 2026 12:31:26 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685885; bh=FbodRPITxWBrOtuufPy3Z6qimg7890iTtZ1cXcmoh4Q=; 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=p6UodCOVm5i2E3TESynIxmgztMXz7xMrVdXQd+HSJGsV54rXbKi0/lal/il8Io4EW M7vMHTwzIUEk1gNS8Aorpa++scIV60JQGrV/SrqYsFXtA5Fhy/+YayK9pZ6jkisDFz n3+6YabvTZ81K22A/o6wbRcP1KkX/uTwD0F2qQ7c/IqMm78mlFCti3dNvQpdC8R6kC 0fH8I663hV1yk4rAvGXu5uyL+Eg4gkRJNjpoXhKAQ05ZTC9bNnQkLEi8octFyWqZdp OcZM2fsrHfVBWEui1jf4mAMkV9AeFXUZixzMSMYopEJyNNi8ujnJubLIduEkrzFlPe chi5SsXs+0TsQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 229C86A07B for ; Mon, 16 Mar 2026 12:31:25 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685880; bh=kmiXXfQiUFfqhJsbEZUptj/+jkY6pVkYCOJckOUkoi8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gh4AkwDtC7G9MujDwk/vaRPQk7F4MNOiBSWR1pefLqZRTzvTdPTREc88Ev1jr0+p7 uwYOvh7YieAsenp5n1Y3aroZfqN6DjzLyUxbzdNlwb1xfLnCP/XysoPx+b3mxpmGgf 2hms2iEFhaaIt4tgPdGvi7HIatOnFubdPvML+YrcZmHo20ADCIYVm6ZziSSu6wnBLk Ggl2c8S2O36CWe1bkjAxArOUrRq2bnXGDdQaFmHbGXjS9nrVC06cl711rp0BfxTtZO Ny0stTK+nZPobnZjJhRpdiJQDELDcNdJGCuE+aPR9FdXEx4d4KErT13uiywSk5hGK/ 0islaOdaYaMjg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4E1B96A08D; Mon, 16 Mar 2026 12:31:20 -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 mM7efshMiMdS; Mon, 16 Mar 2026 12:31:20 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685876; bh=1khvGZ9MgcPeSNJqEsIFlaCGUPHjTiWINDeS0HNe9Bw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HiSpQmSbMQdLC/8dU5dcee1oajtCUifd7Bv+JSf7NxmB+6hUV1joMJ3R0T1bL41Ev n6XVTF4m7I2aVrN772svcjj9oU6ZWmevDcW/3+5yV1c9MAUKgNKB7GxZxqqzvwpffz Dw/YUqAXPNqt15xzC9CBTLXUjoih1cVFbZOT5Tm869cwd0/He4TD3Qfvaqy2McfyQp IfkZVc5m2iuydSVNwr9CDYu5DEbIVrBvt+RVdyQqTdmjR4fTC8/UmCcEdVbsaE+zE3 +JeGDR6A3SDsu0NP81VA4N40BR13eSyDA+6oTFQmTOkkPRi2LY+bLho1Ae2BlW07cD ZtrrHGEUI64zw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 9D8666A07B; Mon, 16 Mar 2026 12:31:16 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 12:30:29 -0600 Message-ID: <20260316183050.3855921-7-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316183050.3855921-1-sjg@u-boot.org> References: <20260316183050.3855921-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 2MLKW45EXAW6NSHCKCRFON35ELOGA4NQ X-Message-ID-Hash: 2MLKW45EXAW6NSHCKCRFON35ELOGA4NQ 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 06/17] test: Add memory leak checking option to ut command 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 -L flag to the ut command that checks for memory leaks around each test. When enabled, mallinfo() is called at the start and end of ut_run_test() and any difference in allocated bytes is reported. This is useful for finding memory leaks in driver model and other subsystems that should be fully cleaned up between tests. Usage: ut -L dm [test_name] Signed-off-by: Simon Glass --- doc/develop/malloc.rst | 22 +++++++++++++++++++++- include/test/test.h | 2 ++ test/cmd_ut.c | 8 +++++++- test/test-main.c | 15 +++++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/doc/develop/malloc.rst b/doc/develop/malloc.rst index 7e46c05dfde..74acc3220af 100644 --- a/doc/develop/malloc.rst +++ b/doc/develop/malloc.rst @@ -500,9 +500,29 @@ by checking ``malloc_get_info()`` before and after:: assert(before.malloc_count == after.malloc_count); assert(before.in_use_bytes == after.in_use_bytes); +**Automatic leak checking with ut -L** + +The ``ut`` command accepts a ``-L`` flag that checks for memory leaks around +each test. It takes a ``mallinfo()`` snapshot at the start of ``ut_run_test()`` +and compares it at the end, after both ``test_pre_run()`` and +``test_post_run()`` have completed:: + + => ut -L dm dm_test_acpi_bgrt + Test: acpi_bgrt: acpi.c + Leak: 448 bytes: acpi_bgrt + ... + +When using uman, pass ``--leak-check``:: + + $ um t --leak-check dm_test_acpi_bgrt + +This makes it easy to scan an entire test suite for leaks:: + + $ um t --leak-check -V dm + **Practical workflow** -1. Add ``ut_check_delta()`` assertions to your test to detect leaks +1. Run ``um t --leak-check -V dm`` (or another suite) to find leaky tests 2. When a leak is detected, add ``malloc_dump_to_file()`` calls before and after the leaking operation 3. Run the test and compare the dump files to identify leaked allocations diff --git a/include/test/test.h b/include/test/test.h index b81cab4d7a4..7d28948eb5f 100644 --- a/include/test/test.h +++ b/include/test/test.h @@ -102,6 +102,7 @@ struct ut_arg { * @arg_error: Set if ut_str/int/bool() detects a type mismatch * @keep_record: Preserve console recording when ut_fail() is called * @emit_result: Emit result line after each test completes + * @leak_check: Check for memory leaks around each test * @video_ctx: Vidconsole context for test message display (allocated on use) * @video_save: Saved framebuffer region for video tests * @priv: Private data for tests to use as needed @@ -139,6 +140,7 @@ struct unit_test_state { bool arg_error; bool keep_record; bool emit_result; + bool leak_check; void *video_ctx; struct abuf video_save; char priv[UT_PRIV_SIZE]; diff --git a/test/cmd_ut.c b/test/cmd_ut.c index f8ff02bdbc7..7de10b32065 100644 --- a/test/cmd_ut.c +++ b/test/cmd_ut.c @@ -258,6 +258,7 @@ static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) bool force_run = false; bool keep_record = false; bool emit_result = false; + bool leak_check = false; int runs_per_text = 1; int workers = 0, worker_id = 0; struct suite *ste; @@ -283,6 +284,9 @@ static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) case 'm': force_run = true; break; + case 'L': + leak_check = true; + break; case 'I': test_insert = str + 1; if (!strchr(test_insert, ':')) @@ -316,6 +320,7 @@ next_arg: ut_init_state(&uts); uts.keep_record = keep_record; uts.emit_result = emit_result; + uts.leak_check = leak_check; uts.workers = workers; uts.worker_id = worker_id; name = argv[0]; @@ -363,9 +368,10 @@ next_arg: } U_BOOT_LONGHELP(ut, - "[-Efmrs] [-R] [-I:] [-P:] [ [...]]\n" + "[-ELfmrs] [-R] [-I:] [-P:] [ [...]]\n" " - run unit tests\n" " -E Emit result line after each test\n" + " -L Check for memory leaks around each test\n" " -r Number of times to run each test\n" " -f/-m Force 'manual' tests to run as well\n" " -I Test to run after other tests have run\n" diff --git a/test/test-main.c b/test/test-main.c index 77223cfbcb7..be13084ed92 100644 --- a/test/test-main.c +++ b/test/test-main.c @@ -631,6 +631,7 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test, { const char *fname = strrchr(test->file, '/') + 1; const char *note = ""; + struct mallinfo leak_before; int old_fail_count; int ret; @@ -638,6 +639,9 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test, note = " (flat tree)"; printf("Test: %s: %s%s\n", test_name, fname, note); + if (uts->leak_check) + leak_before = mallinfo(); + /* Allow access to test state from drivers */ ut_set_state(uts); @@ -659,6 +663,17 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test, ut_set_state(NULL); + if (uts->leak_check) { + struct mallinfo leak_after; + int diff; + + leak_after = mallinfo(); + diff = leak_after.uordblks - leak_before.uordblks; + if (diff) + printf("Leak: %d bytes: %s%s\n", diff, test_name, + note); + } + if (uts->emit_result) { bool passed = uts->cur.fail_count == old_fail_count; From patchwork Mon Mar 16 18:30:30 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2018 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=1773685886; bh=ACr2PCjqNHBfC48nwguGN7vto1NXH39pOGA7kcwF1Xs=; 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=RacZiG6lGeCtcrohdQNEqKzun++S+EAOqpUxdSK0eKr0qKu7kWHrg1JFF3/N4sxL8 OkkLiP5Xzl/4g359qHVDnycHJB6UMnjviaUusf4jiUJojPyEYSCYjep1SKlnJVGltD J/+1pQHUoIiRfVDXGzTaacnN8Y/YiR5N6asRdmZcBrVNYzn+bKOXLZGVDMdsbeHkx5 oZSOMSIBRSyPCJ6T5CIhgJ+AHr1/5HGOe2FtOvS98DTV3vhSKqnrwDVOpfrFNHennv A2UgqkIS426L0Y99xa2y8GKQuoHqGgY2HSSakEeyO0dUSrrhh4pUUxJCGBnncdkCvJ 9eehrgKckchjw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CEC516A0A5 for ; Mon, 16 Mar 2026 12:31:26 -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 2mNvegKotkaz for ; Mon, 16 Mar 2026 12:31:26 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685886; bh=ACr2PCjqNHBfC48nwguGN7vto1NXH39pOGA7kcwF1Xs=; 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=RacZiG6lGeCtcrohdQNEqKzun++S+EAOqpUxdSK0eKr0qKu7kWHrg1JFF3/N4sxL8 OkkLiP5Xzl/4g359qHVDnycHJB6UMnjviaUusf4jiUJojPyEYSCYjep1SKlnJVGltD J/+1pQHUoIiRfVDXGzTaacnN8Y/YiR5N6asRdmZcBrVNYzn+bKOXLZGVDMdsbeHkx5 oZSOMSIBRSyPCJ6T5CIhgJ+AHr1/5HGOe2FtOvS98DTV3vhSKqnrwDVOpfrFNHennv A2UgqkIS426L0Y99xa2y8GKQuoHqGgY2HSSakEeyO0dUSrrhh4pUUxJCGBnncdkCvJ 9eehrgKckchjw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 833416A081 for ; Mon, 16 Mar 2026 12:31:26 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685880; bh=Sm/5YlCHfkAHrXqaAMlH67q8w+Gi/yOKTy1OlzEpO4A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uAUNYqmx9faCF1ZZUwKBo5LqFPC015uQMGTbxTBoZcq2laAIaxqC0NTKmiKs6glBc 7LZl5MAq1OzbmBsgFTDqgVPQ08FC6VjblyTYGEkTBWhkaovtyldjqsKqpZ6PkcZyb6 hm5+GYRixlKqppy3czuLvW44/MEjzMFD1v/nw58aLTtWEI+v9jk3xle+hXw+Bj9/RE Tbow1klXAoIhtVyp3GXw2tU45W9c+hQkT34bb/oE825dt7sJrBh49vJo7fmZvpiWyo puJBTU7HFqNo+A2TLhDJL0hYEGjHADRb5+cMjTw/dDxIk+y2k5i5m7V/K74uetTqiQ 1FIoUg1GzHJ9w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 61CA36A09B; Mon, 16 Mar 2026 12:31:20 -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 kO9LXVoah9wI; Mon, 16 Mar 2026 12:31:20 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685877; bh=EvAEZ4u4pYM5C/Tz4u0KKFHFGG2X8WaW+M6L3xbe6rY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YaGWwdEOTCnnDn6LLhjKf+N5/tlDlhGMOkQ0BIWXLHboctZOum2tQHCPpVozDZPPn OlGYdfkBSVTvCQWZdZgXn6FNo8RhHjaGM/cvt9HrNpkMNDifLkUEOVuOx4hEZlGOn8 TrzkEoknnXyC6pc2yhrOkL5eOdPLV9tQiKQIY1fU0Uc7JNLyAVqzJued6vsd+0iIHK t4CYw+7iofW3N50mZUdkC03kMC+dNOlgoZXNI3o3WCcANgIA27WyT9nD8PUO++huGA 4aLGcawQMt2eyhBSghC47218kF9I9MziRqKbF7JV5nvjjXS78cwOp4WdVxnm/NCwSF eVBbzYB9wYmog== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 6DC2D6A09E; Mon, 16 Mar 2026 12:31:17 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 12:30:30 -0600 Message-ID: <20260316183050.3855921-8-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316183050.3855921-1-sjg@u-boot.org> References: <20260316183050.3855921-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: HTJNUOB6W2JEBR7TT3CELVB3PY5BCVGU X-Message-ID-Hash: HTJNUOB6W2JEBR7TT3CELVB3PY5BCVGU 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 07/17] test: Show leaked allocations with ut -L 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 Use the new malloc_leak_check functions to show the address, size and caller backtrace of each leaked allocation, rather than just the total byte count. Example output: Test: acpi_bgrt: acpi.c Leak: 2 allocs 14a5c5c0 110 stdio_clone:230 <-stdio_register_dev:244 14a5c6d0 b0 map_to_sysmem:210 <-video_post_probe:823 Signed-off-by: Simon Glass --- doc/develop/malloc.rst | 30 +++++++++++++++++------------- test/test-main.c | 21 +++++++++++---------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/doc/develop/malloc.rst b/doc/develop/malloc.rst index 74acc3220af..6bb17dca7b1 100644 --- a/doc/develop/malloc.rst +++ b/doc/develop/malloc.rst @@ -503,14 +503,21 @@ by checking ``malloc_get_info()`` before and after:: **Automatic leak checking with ut -L** The ``ut`` command accepts a ``-L`` flag that checks for memory leaks around -each test. It takes a ``mallinfo()`` snapshot at the start of ``ut_run_test()`` -and compares it at the end, after both ``test_pre_run()`` and -``test_post_run()`` have completed:: +each test. It snapshots every in-use heap chunk at the start of +``ut_run_test()`` and compares after both ``test_pre_run()`` and +``test_post_run()`` have completed. Any new allocations are reported with +their address, size and caller backtrace:: - => ut -L dm dm_test_acpi_bgrt + => ut -LE dm dm_test_acpi_bgrt Test: acpi_bgrt: acpi.c - Leak: 448 bytes: acpi_bgrt - ... + Leak: 2 allocs + 14a5c5c0 110 stdio_clone:230 <-stdio_register_dev:244 <-vidconsole_post_probe:961 + 14a5c6d0 b0 map_to_sysmem:210 <-video_post_probe:823 <-device_probe:589 + Result: PASS: acpi_bgrt: acpi.c + +The snapshot is stored using ``os_malloc()`` so it does not affect the +heap being measured. Caller backtraces are available when +``CONFIG_MCHECK_HEAP_PROTECTION`` is enabled (the default for sandbox). When using uman, pass ``--leak-check``:: @@ -523,13 +530,10 @@ This makes it easy to scan an entire test suite for leaks:: **Practical workflow** 1. Run ``um t --leak-check -V dm`` (or another suite) to find leaky tests -2. When a leak is detected, add ``malloc_dump_to_file()`` calls before and - after the leaking operation -3. Run the test and compare the dump files to identify leaked allocations -4. Use the caller backtrace in the dump to find the allocation site -5. If more detail is needed, enable ``malloc_log_start()`` to trace all - allocations during the operation -6. Fix the leak and verify the test passes +2. Use the caller backtrace in the ``-L`` output to find the allocation site +3. If more detail is needed, add ``malloc_dump_to_file()`` calls or enable + ``malloc_log_start()`` to trace all allocations during the operation +4. Fix the leak and verify the test passes **Dumping heap state on exit** diff --git a/test/test-main.c b/test/test-main.c index be13084ed92..09458fa91da 100644 --- a/test/test-main.c +++ b/test/test-main.c @@ -631,7 +631,7 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test, { const char *fname = strrchr(test->file, '/') + 1; const char *note = ""; - struct mallinfo leak_before; + struct malloc_leak_snap leak_snap = {}; int old_fail_count; int ret; @@ -640,7 +640,7 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test, printf("Test: %s: %s%s\n", test_name, fname, note); if (uts->leak_check) - leak_before = mallinfo(); + malloc_leak_check_start(&leak_snap); /* Allow access to test state from drivers */ ut_set_state(uts); @@ -664,14 +664,15 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test, ut_set_state(NULL); if (uts->leak_check) { - struct mallinfo leak_after; - int diff; - - leak_after = mallinfo(); - diff = leak_after.uordblks - leak_before.uordblks; - if (diff) - printf("Leak: %d bytes: %s%s\n", diff, test_name, - note); + int leaks; + + leaks = malloc_leak_check_count(&leak_snap); + if (leaks > 0) { + printf("Leak: %d allocs\n", leaks); + malloc_leak_check_end(&leak_snap); + } else { + malloc_leak_check_free(&leak_snap); + } } if (uts->emit_result) { From patchwork Mon Mar 16 18:30:31 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2019 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=1773685887; bh=rx0VSRRi9KQ6tqEFDzPSo7DaahePzTatFyurrMkKnm4=; 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=d4P99gQWLAd9eRtGgDtR7bQjETV2wyvg4H/R7u843d7MmX1cRyF+cfs/dcvFZpB10 CUfbJFOm+I+j9qlTho4eKqUxPNUDi3O2i32dL8TGWbiMsT/m2yLit7tTgLzssB35F3 J3n3gDGxFuMr1+xgIiCSAZsIwTIRuM+z+3ZLgm+0o6lZAQyJjTJQnjX8mysT+j5FAp o4BDoabjvRUgILeYx0S97b5dn4hdokIvhpdtA8CIwqnTkJVIynem2FdTC+BgHYLQnZ awNMzh3hRspxLpRzn0nrpwRd88TJSNEBW1OUvr92++JJjSLM2ZVWLeNzbi+8ocWfL0 +BE+bh87TjYzQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 78BAA6A09B for ; Mon, 16 Mar 2026 12:31:27 -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 iMGQVTHZ_ilY for ; Mon, 16 Mar 2026 12:31:27 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685887; bh=rx0VSRRi9KQ6tqEFDzPSo7DaahePzTatFyurrMkKnm4=; 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=d4P99gQWLAd9eRtGgDtR7bQjETV2wyvg4H/R7u843d7MmX1cRyF+cfs/dcvFZpB10 CUfbJFOm+I+j9qlTho4eKqUxPNUDi3O2i32dL8TGWbiMsT/m2yLit7tTgLzssB35F3 J3n3gDGxFuMr1+xgIiCSAZsIwTIRuM+z+3ZLgm+0o6lZAQyJjTJQnjX8mysT+j5FAp o4BDoabjvRUgILeYx0S97b5dn4hdokIvhpdtA8CIwqnTkJVIynem2FdTC+BgHYLQnZ awNMzh3hRspxLpRzn0nrpwRd88TJSNEBW1OUvr92++JJjSLM2ZVWLeNzbi+8ocWfL0 +BE+bh87TjYzQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 18C936A0AC for ; Mon, 16 Mar 2026 12:31:27 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685880; bh=wtb4B22sKhZuaV/j0OJnsR5Yto/M78OVn6rH4Kxdr20=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l5I9bLfq7JE8ojwZJtz77f9nxJi7M2Pgu8An9F1pWT6DejhrdIZYuk+cBKQrg3wz7 rtY5Nb6qseCWGcWpYfK4c7nPfEQT0C6Nk4+aUd3z38kzGXcs1Sv8nAN/bz63RX+pb2 R69QQFnWFQkFmLyrWkwjQuD/GCoNmvRA9hMl/nDb/Wl4x7AONigg23jh8HeuyAfNJC CdQ06LU8YynYg+DnoKtFbQ9ex7m0logLCe/O7Hd3F2ArfbxS4zp8dTLjV+7OzRkzWl muKxn2lvsNMX6umS7wr0SMLm1XcnjseiqO1E/IWykm/GmAvKOsVrEKm31yhIsUpBja mntKkpDC3lIlg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 61C896A07B; Mon, 16 Mar 2026 12:31:20 -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 X0rKh8H51pvQ; Mon, 16 Mar 2026 12:31:20 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685878; bh=ltAg2Ffak6sUHbMdSZkPXTAALgIqIHs+Akk+cdTTyP8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R0YALA4a2RaF07HaqqxQiZHpyvMdR6DqRvNdj5saLBAy0C/jfeovGZoQK56htX034 RaUvp1xxvdOg+inqDPaYx7nla1H+7U85pllKZvndnjKpLNZeTen6K7oizEvF/xNlCf /Coebm/AMzxYSRLYCdAM3Y3OUdcz30b4iv3aRk6a+WWDB1YNx5dOZmNEKMIzzbW45o E9fEBoqwcTUZO1uS6i9gELF3OGOS2hE4AcLOhC9ChTHwcsbr6dBnzAdTxwRMJ2yKgC UXg9IAmPRm+WIpG/pkOsO5Fvdw6VdeoCmm2bG4+R+lkVWwtDFzqkC65Er/iBasZNSc JEtCASWyX/L/A== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 4B3CF6A0A6; Mon, 16 Mar 2026 12:31:18 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 12:30:31 -0600 Message-ID: <20260316183050.3855921-9-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316183050.3855921-1-sjg@u-boot.org> References: <20260316183050.3855921-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: V3BBJIQMIBA5FKDQTCU2APBGASHJVOFC X-Message-ID-Hash: V3BBJIQMIBA5FKDQTCU2APBGASHJVOFC 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 08/17] test: Reset malloc backtrace collection before each test 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 stack-protector test and __stack_chk_fail() call malloc_backtrace_skip(true) to prevent crashes when collecting backtraces from a corrupted stack. However, they never reset it, so all subsequent allocations in a long-running session (e.g. pytest) have empty caller backtraces. Add malloc_backtrace_unbusy() to clear the reentrant guard which can also get stuck if backtrace collection crashes. Reset both flags at the start of each test in test_pre_run() Signed-off-by: Simon Glass --- common/dlmalloc.c | 24 ++++++++++++++++++++++++ include/malloc.h | 30 ++++++++++++++++++++++++++++++ test/test-main.c | 8 ++++++++ 3 files changed, 62 insertions(+) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index e61f565bbab..f05d7ae83c5 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -5986,6 +5986,30 @@ void malloc_backtrace_skip(bool skip) #endif } +void malloc_backtrace_unbusy(void) +{ +#if CONFIG_IS_ENABLED(MCHECK_BACKTRACE) + in_backtrace = false; +#endif +} + +bool malloc_backtrace_is_active(bool *skipp, bool *busyp) +{ +#if CONFIG_IS_ENABLED(MCHECK_BACKTRACE) + if (skipp) + *skipp = mcheck_skip_backtrace; + if (busyp) + *busyp = in_backtrace; + return !mcheck_skip_backtrace && !in_backtrace; +#else + if (skipp) + *skipp = false; + if (busyp) + *busyp = false; + return false; +#endif +} + static const char *mcheck_caller(void) { #if CONFIG_IS_ENABLED(MCHECK_BACKTRACE) diff --git a/include/malloc.h b/include/malloc.h index ded5520ca23..05d4c06fb89 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -827,10 +827,40 @@ int malloc_log_entry(uint idx, struct mlog_entry **entryp); * * @skip: true to skip backtrace collection, false to enable it */ + +/** + * malloc_backtrace_unbusy() - Clear the backtrace reentrant guard + * + * The malloc backtrace collector sets a guard flag while collecting a + * backtrace to prevent re-entrancy. If a crash or longjmp occurs during + * collection, the guard stays set and all subsequent backtraces are + * silently skipped. Call this to reset it. + */ + +/** + * malloc_backtrace_is_active() - Check whether backtrace collection works + * + * @skipp: If non-NULL, returns true if collection is disabled via + * malloc_backtrace_skip() + * @busyp: If non-NULL, returns true if the reentrant guard is stuck + * Return: true if backtrace collection is active (neither skipped nor busy) + */ #if CONFIG_IS_ENABLED(MCHECK_HEAP_PROTECTION) void malloc_backtrace_skip(bool skip); +void malloc_backtrace_unbusy(void); +bool malloc_backtrace_is_active(bool *skipp, bool *busyp); #else static inline void malloc_backtrace_skip(bool skip) {} +static inline void malloc_backtrace_unbusy(void) {} +static inline bool malloc_backtrace_is_active(bool *skipp, bool *busyp) +{ + if (skipp) + *skipp = false; + if (busyp) + *busyp = false; + + return false; +} #endif /** diff --git a/test/test-main.c b/test/test-main.c index 09458fa91da..06bb0ff6e1b 100644 --- a/test/test-main.c +++ b/test/test-main.c @@ -464,6 +464,14 @@ static int dm_test_restore(struct device_node *of_root) */ static int test_pre_run(struct unit_test_state *uts, struct unit_test *test) { + /* + * Reset backtrace collection in case a previous test disabled it + * (e.g. stack-protector test via __stack_chk_fail) or a crash + * left the reentrant guard set. + */ + malloc_backtrace_skip(false); + malloc_backtrace_unbusy(); + ut_assertok(event_init()); /* From patchwork Mon Mar 16 18:30:32 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2020 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=1773685890; bh=E1EBwnSZFMur53S/tUomr3J0qIRXfRfMSJplSqSNpQ8=; 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=LMB7ArpDBYMg9H29SAvo8ZhUt1QQIy9gR5lt3f1xXubhXFuHH7V/z7C8+G1GJ1hG1 LYny+MEXa83sZ3Tde7TPQxvjurKALtb2St8NZRg1Ju6Kybzm6NOVvQl2wmWgq2DSIf vglWKGQqqdr+nY2LWK5rneSmtLBGeT7r1+S6cJIHijV3co8yHXC4ewY07C2eLT6dth TMUHCqGRb9JHoN199AFzaGxY8Kht1zdM2G74K/SMG7s+19SB3AwYZY9QcxvRJzGzC6 Ffk2v1zdgCKjOJ5PFjWTfCfWdJ2RKct5S+gHlPrD416XQnBeWwOrdCv46AgMONhhk3 GL1FAmXAE9Isw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 06EBD6A081 for ; Mon, 16 Mar 2026 12:31:30 -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 grD0Uwi1eiuM for ; Mon, 16 Mar 2026 12:31:29 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685887; bh=E1EBwnSZFMur53S/tUomr3J0qIRXfRfMSJplSqSNpQ8=; 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=emslsM5mf2DPw7kdbj8tO169REQ23Psy8grE/YBMqrGWen9r3WyBbginrjdlG0z1N S6Cy8lECFRYvFgOa7Hw/ovTMrme8d0x9+IkM39Pzc5eIsVaH2lnklHPtpeCNwF8gow BIKECRHB7gOtAFPGoCl5WNNsiGM4ClrHj9rxXISXqFlSZ5aJkyUd+3e3an1c26ef7W Y2Hy4r68CBaW5H8MPYkrO8F73XxXejOBV1tflDxtDhB3YbLhrByKshDaIO5kPpw83H 0Bu/uOF8/tiPipX+WZd2vRe8CLTu5100o9s1HLbAs50Ix0rcLP18MiGpkGpw+MIGxF EXSksZ6CMSkNw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A117F6A0B1 for ; Mon, 16 Mar 2026 12:31:27 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685880; bh=DFNCvghN99hxGJtJm8SY/c+kW68EK0Nqk0AeEopvFaA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E3M4X8T+wRqJa6yjJ9nTx7krfDwBEAATrGKnPImlm1jZkmWM2X/uaMMUhjU7bdoMq F7X/cvSH8fYjaXrc6kwbuL0gcgKbPZzEwP9YkV0LerejQCbxYmiiyo+Rvfhqh32Ue/ B1xU2+Zw7kORrxguI6wfbElJbMj9JWqkNyc+AvQnpOowmRi3EK+q9If4daAu6CkvnY CAz/zjLc6MEae9XdodPccp16CQ/lHdyLWD1gs7DspHb32ENTfwXO/I9sFXo6J9HjAE Pf876iAAFHI/3l232bq9FtlDubb287iCr5ON+MDuVEZ4Pz4QwXdq0+Oos5QaIq9G+W n4E139vWVIxCg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 751A26A09C; Mon, 16 Mar 2026 12:31:20 -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 d2rl3-zghZcx; Mon, 16 Mar 2026 12:31:20 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685879; bh=fTdqaMkB/ZjNsWLP93lWzDAbGd9djz7MrDFH0DOPBbc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jTeEc55rCoDNHTQD2eYoBO42oaBjwKmNc1WZdq/2NRDeoSlsA8HQTV7p5otskVP9V Kp8Y1GoJyCMpIZw+OUR7joAVE50N0vNz8AT3sffeGinyS2YGIPqvx8IRib/4iCdsjZ BfXkwb3AsL5cp/73cDb0qfpkrhRC2fNEkE1lsNBE0pGIUPCAAZ0xO6BQW0y/gaDzb3 u/bOSRkc85k7udXS/0rHgzD12Uao3nH+iXSYMZ9+L1GRwkpeJ5WKCvQoXYM7sK/k9c qC4d+moC+2p5d2Xp3QAEOSwKnLfq3SJgMOUT0pGRJskt5Voy/hKcbuLKiQjJ7ExkzF PlTR5KAuQUkrw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 35BA16A081; Mon, 16 Mar 2026 12:31:19 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 12:30:32 -0600 Message-ID: <20260316183050.3855921-10-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316183050.3855921-1-sjg@u-boot.org> References: <20260316183050.3855921-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: UPLCSGBMFEEJU65GHFD6QCWJRGKBXH4K X-Message-ID-Hash: UPLCSGBMFEEJU65GHFD6QCWJRGKBXH4K 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 09/17] cmd: malloc: Add leak subcommand 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 'malloc leak' subcommands for interactive heap-leak detection at the U-Boot command line: malloc leak start - snapshot current heap allocations malloc leak - count new allocations (keeps the snapshot) malloc leak end - print and count new allocations, free snapshot Each leaked allocation is printed with its address, size and caller backtrace (when mcheck is enabled). Guarded by CONFIG_CMD_MALLOC_LEAK which depends on CONFIG_SANDBOX since the snapshot uses os_malloc() for storage. Signed-off-by: Simon Glass --- cmd/Kconfig | 10 +++++++ cmd/malloc.c | 65 ++++++++++++++++++++++++++++++++++++++++++ doc/develop/malloc.rst | 32 +++++++++++++++++++-- test/cmd/malloc.c | 52 +++++++++++++++++++++++++++++++++ 4 files changed, 157 insertions(+), 2 deletions(-) diff --git a/cmd/Kconfig b/cmd/Kconfig index 4af032233b9..f9d6ea46566 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -3139,6 +3139,16 @@ config CMD_MALLOC about memory allocation, such as total memory allocated and currently in use. +config CMD_MALLOC_LEAK + bool "malloc leak - Detect heap leaks" + depends on CMD_MALLOC && SANDBOX + default y + help + This adds the 'malloc leak' subcommand which snapshots the heap + and later reports any new allocations. Use 'malloc leak start' + before an operation and 'malloc leak end' afterwards to see + leaked allocations with their caller backtraces. + config CMD_MALLOC_LOG bool "malloc log - Log malloc traffic" depends on CMD_MALLOC && MCHECK_LOG diff --git a/cmd/malloc.c b/cmd/malloc.c index e7362a39bd2..6b019f4c056 100644 --- a/cmd/malloc.c +++ b/cmd/malloc.c @@ -62,6 +62,69 @@ static int __maybe_unused do_malloc_log(struct cmd_tbl *cmdtp, int flag, return 0; } +static struct malloc_leak_snap leak_snap; + +static int __maybe_unused do_malloc_leak(struct cmd_tbl *cmdtp, int flag, + int argc, char *const argv[]) +{ + if (argc < 2) { + int leaks; + + if (!leak_snap.addr) { + printf("No snapshot taken, use 'malloc leak start'\n"); + return CMD_RET_FAILURE; + } + + leaks = malloc_leak_check_count(&leak_snap); + if (leaks > 0) + printf("%d new allocs\n", leaks); + else + printf("No leaks\n"); + + return 0; + } + + if (!strcmp(argv[1], "start")) { + int ret; + + if (leak_snap.addr) + malloc_leak_check_free(&leak_snap); + ret = malloc_leak_check_start(&leak_snap); + if (ret) + return CMD_RET_FAILURE; + printf("Heap snapshot: %d allocs\n", leak_snap.count); + } else if (!strcmp(argv[1], "end")) { + int leaks; + + if (!leak_snap.addr) { + printf("No snapshot taken, use 'malloc leak start'\n"); + return CMD_RET_FAILURE; + } + + leaks = malloc_leak_check_end(&leak_snap); + if (leaks > 0) + printf("%d leaked allocs\n", leaks); + else + printf("No leaks\n"); + } else { + return CMD_RET_USAGE; + } + + return 0; +} + +#if CONFIG_IS_ENABLED(CMD_MALLOC_LEAK) +#define MALLOC_LEAK_HELP \ + "malloc leak [start|end] - detect heap leaks\n" \ + " start - snapshot current heap allocations\n" \ + " end - show allocations not in the snapshot\n" \ + " (none) - count new allocations without freeing snapshot\n" +#define MALLOC_LEAK_SUBCMD , U_BOOT_SUBCMD_MKENT(leak, 3, 1, do_malloc_leak) +#else +#define MALLOC_LEAK_HELP +#define MALLOC_LEAK_SUBCMD +#endif + #if CONFIG_IS_ENABLED(CMD_MALLOC_LOG) #define MALLOC_LOG_HELP \ "malloc log [start|stop|dump] - log malloc traffic\n" \ @@ -77,9 +140,11 @@ static int __maybe_unused do_malloc_log(struct cmd_tbl *cmdtp, int flag, U_BOOT_LONGHELP(malloc, "info - display malloc statistics\n" "malloc dump - dump heap chunks (address, size, status)\n" + MALLOC_LEAK_HELP MALLOC_LOG_HELP); U_BOOT_CMD_WITH_SUBCMDS(malloc, "malloc information", malloc_help_text, U_BOOT_SUBCMD_MKENT(info, 1, 1, do_malloc_info), U_BOOT_SUBCMD_MKENT(dump, 1, 1, do_malloc_dump) + MALLOC_LEAK_SUBCMD MALLOC_LOG_SUBCMD); diff --git a/doc/develop/malloc.rst b/doc/develop/malloc.rst index 6bb17dca7b1..ecaf8af3c3e 100644 --- a/doc/develop/malloc.rst +++ b/doc/develop/malloc.rst @@ -527,12 +527,40 @@ This makes it easy to scan an entire test suite for leaks:: $ um t --leak-check -V dm +**Interactive leak checking with the malloc command** + +The ``malloc leak`` command provides interactive leak detection at the +U-Boot command line. Take a snapshot before an operation and check +afterwards:: + + => malloc leak start + Heap snapshot: 974 allocs + => setenv foo bar + => malloc leak end + 14a2a9a0 90 sandbox_strdup:353 <-hsearch_r:403 <-env_do_env_set:130 + 14a2aa30 90 sandbox_strdup:353 <-hsearch_r:403 <-env_do_env_set:130 + 2 leaked allocs + +Use ``malloc leak`` (without arguments) to check the count without +releasing the snapshot, so you can continue testing:: + + => malloc leak start + Heap snapshot: 974 allocs + => + => malloc leak + No leaks + => + => malloc leak + 3 new allocs + => malloc leak end + ... + **Practical workflow** 1. Run ``um t --leak-check -V dm`` (or another suite) to find leaky tests 2. Use the caller backtrace in the ``-L`` output to find the allocation site -3. If more detail is needed, add ``malloc_dump_to_file()`` calls or enable - ``malloc_log_start()`` to trace all allocations during the operation +3. If more detail is needed, use ``malloc leak start`` / ``malloc leak end`` + interactively, or enable ``malloc_log_start()`` to trace all allocations 4. Fix the leak and verify the test passes **Dumping heap state on exit** diff --git a/test/cmd/malloc.c b/test/cmd/malloc.c index 75e8afdec63..95809845dd7 100644 --- a/test/cmd/malloc.c +++ b/test/cmd/malloc.c @@ -54,6 +54,58 @@ static int cmd_test_malloc_dump(struct unit_test_state *uts) } CMD_TEST(cmd_test_malloc_dump, UTF_CONSOLE); +/* Test 'malloc leak' command using the C API directly */ +static int cmd_test_malloc_leak(struct unit_test_state *uts) +{ + struct malloc_leak_snap snap = {}; + ulong chunk_addr; + size_t chunk_sz; + void *ptr; + int ret; + + /* Take a snapshot, then check with no leaks */ + ut_assertok(malloc_leak_check_start(&snap)); + ut_assert(snap.count > 0); + ut_asserteq(0, malloc_leak_check_count(&snap)); + + /* Allocate something and check it is detected */ + ptr = malloc(0x42); + ut_assertnonnull(ptr); + ut_asserteq(1, malloc_leak_check_count(&snap)); + + /* Verify freeing clears the leak */ + free(ptr); + ut_asserteq(0, malloc_leak_check_count(&snap)); + + /* Re-allocate so end has something to print */ + ptr = malloc(0x42); + ut_assertnonnull(ptr); + + /* End should print the leaked allocation and free the snapshot */ + ret = malloc_leak_check_end(&snap); + ut_asserteq(1, ret); + + /* + * Check the output line shows the correct chunk address and chunk + * size. The chunk address is the malloc pointer minus the mcheck + * header. The caller name is only available with mcheck. + */ + chunk_addr = (ulong)ptr - malloc_mcheck_hdr_size(); + chunk_sz = malloc_chunk_size(ptr); + if (IS_ENABLED(CONFIG_MCHECK_HEAP_PROTECTION)) + ut_assert_nextlinen(" %lx %zx %s:", chunk_addr, chunk_sz, + __func__); + else + ut_assert_nextlinen(" %lx %zx ", chunk_addr, chunk_sz); + ut_assert_console_end(); + ut_assertnull(snap.addr); + + free(ptr); + + return 0; +} +CMD_TEST(cmd_test_malloc_leak, UTF_CONSOLE); + #if CONFIG_IS_ENABLED(MCHECK_LOG) /* Test 'malloc log' command */ static int cmd_test_malloc_log(struct unit_test_state *uts) From patchwork Mon Mar 16 18:30:33 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2022 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=1773685890; bh=ZJZB+1xorS0ePm/jUp9nNaAKFIPLUtKcJG49J4VaYPg=; 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=v9A2Y9iVezzIO+6EKZrMTBDNRFsTb4sv6xo+ai+r5Xft9mcw7yWmphPShd8QZbX+y fZzKomOTieOgVBzqxAU2iNqTqEhm4i3IwuPdoOOE8HN/4ggSL/Gh+dqsnFfVKVL5ej ZrxcRwALrLVHTjW3ZFCF6+l7bR73z3kzdE5L4Cr2MnbaUSjCxR2BVS+vOEUk6PTVo4 soOMVTbCL/8lGgFp4EFjNXWJUD200M1X9o2Ged3gZLrbYa8kFxtYFAQrRO00i2uV2A q7BV3e9QVhvbZkci9SuMhPxs+xCre46NdZKqg8cytRuOxJxmY+qtKwSylnN1gn4FI6 17uw2ybcMrncg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 96C956A0B6 for ; Mon, 16 Mar 2026 12:31:30 -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 FwXdmRObNO0e for ; Mon, 16 Mar 2026 12:31:30 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685888; bh=ZJZB+1xorS0ePm/jUp9nNaAKFIPLUtKcJG49J4VaYPg=; 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=bSHEsgGOp4Qeq2uUZm/wRfqt5cMUMQkUOPkStJpcLGX3w0mS3TsPxrvi7D0WqfK80 8B31LgTNs489FVxKgT0LNOA5/OgdQ7Ej8gUhvYfPCc3ryJP2UpTeFYR72+YCcApPUs +lB64HSvRar6d3d/ljynzmTWPzybdoJTi2kITp8fj28W/uEBElh9RdVReihjbPpUs9 rsUmnd7PP//ByMy7RcOIc6Twzv1BUhcZOHKkogyCJozEdgCuhP6g318lAXQGajtIOf SENXFEzglJzWkxlgmbzvbZnZdGLRGavrtioldVEv2+TBZyHteljRzvoQs+PGN8sngT rYWwbiAe+DB+w== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 93ACF6A0BE for ; Mon, 16 Mar 2026 12:31:28 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685882; bh=IE+waU+nj5oo5PCB4DYcwQvXeyRGYj1tGt2ts4IHYvA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ICaY3rPWZSNHquL4zGExj4DzwPLKZVNEur4UQFT1GNNuNgTu3vgLgpSxW4tgscYA3 rgnbzlRyJwZGWErbCMyMje+hV/za0rbxBmFhspHfUrulKKeL3Qy9OVI558alroNqNO Z15L9eRor32bCOjtkqsyjPjkHtiW8n+EE+HXJBbEIuz3jQt+KkNoucE+gVYDUxw6xu vhsA4LRwd3LqLJC7nkK+HDcPb4SAk3Oz6EWZyZqZ5Is23N9wVoO5fH8JNdKJNfRjE1 socJb2N9HD9Ez3rIB9ya6oQDZ3mbY1ZFl+FGTD/GDEC9dQsj6g/XUDsK6EuAKUfrkh hMjgN3XDSBdhg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8BCCA6A09F; Mon, 16 Mar 2026 12:31:22 -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 hSgI5TAdPldG; Mon, 16 Mar 2026 12:31:22 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685880; bh=hWkd8UCy/Cg0n3zE92xZKZsIaWz814mAEiu5fWdT5Nw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aO4XpTdbmpJYU/MAkMTF91Fuw0unn4hrwXuS3VIoP7QoXak41/eNuBWeMORgW/sLV GUrgCO/vtrzT4x/W78V6D/wZGyTPDfWGZroPB7xMpLHU7EDr2MYluhXsfa7hsbWZX2 GnBI4tl3XHqqPJx3jMYncuVTYrA1YFaWEO9spp3u6Clsbk4k5XIza1flEeM/Dv3VWE 5u3rI4WeM0MkV4uCfR9w7+O6ANeAXp5fe/bM5AsO2Mze1y9kcCvTu48fR89EjJwnXG JhkXJV8gxIxkPTqV+HZtYVAeRWJ+g+no4L7equU5x2Diwwr/DLEcnqfJGnsks4nBWw +z3UnOzUw3SGA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 14CC46A078; Mon, 16 Mar 2026 12:31:20 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 12:30:33 -0600 Message-ID: <20260316183050.3855921-11-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316183050.3855921-1-sjg@u-boot.org> References: <20260316183050.3855921-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: FQQJM6RLH2AYILFFPWP2CA3N6ESO3IOJ X-Message-ID-Hash: FQQJM6RLH2AYILFFPWP2CA3N6ESO3IOJ 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 10/17] test: py: Add --leak-check option to pytest 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 --leak-check flag to the pytest command line that passes -L to every ut invocation, enabling per-test heap-leak detection. Leaked allocations are printed with their address, size and caller backtrace. For example: test/py/test.py -B sandbox --leak-check -k dm_test_acpi_bgrt Signed-off-by: Simon Glass --- test/py/conftest.py | 3 +++ test/py/tests/test_ut.py | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/test/py/conftest.py b/test/py/conftest.py index 47a0d112e51..303a697d76a 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -106,6 +106,8 @@ def pytest_addoption(parser): help='Disable console timeout (useful for debugging)') parser.addoption('--no-full', default=False, action='store_true', help='Skip flat-tree tests (run live-tree only)') + parser.addoption('--leak-check', default=False, action='store_true', + help='Check for memory leaks around each unit test') parser.addoption('--malloc-dump', default=None, help='Write malloc dump to file on exit') @@ -364,6 +366,7 @@ def pytest_configure(config): ubconfig.allow_exceptions = config.getoption('allow_exceptions') ubconfig.no_timeout = config.getoption('no_timeout') ubconfig.no_full = config.getoption('no_full') + ubconfig.leak_check = config.getoption('leak_check') ubconfig.malloc_dump = config.getoption('malloc_dump') env_vars = ( diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index e64ccd407a0..21a948b4ac6 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -142,11 +142,13 @@ def test_ut(ubman, ut_subtest): execute command 'ut foo bar' """ + flags = '-L ' if ubman.config.leak_check else '' + if ut_subtest == 'hush hush_test_simple_dollar': # ut hush hush_test_simple_dollar prints "Unknown command" on purpose. with ubman.disable_check('unknown_command'): - output = ubman.run_command('ut ' + ut_subtest) + output = ubman.run_command(f'ut {flags}' + ut_subtest) assert 'Unknown command \'quux\' - try \'help\'' in output else: - output = ubman.run_command('ut ' + ut_subtest) + output = ubman.run_command(f'ut {flags}' + ut_subtest) assert output.endswith('failures: 0') From patchwork Mon Mar 16 18:30:34 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2021 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=1773685890; bh=rLil9DMUxyJ9cusWpTdgPBTruIMJUW11PbCSQwuO4OY=; 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=C4IC4uPv5/gKYlq/s1yVp26GlrH8XmYva59eOwGiLLIeinJe5m4aOBFev0xiOM30N Qagkbb2h94aowXHiYDY752B65PrayhvUbLffedn0K02Th7yt+MumeDGmFwryIx2Ia7 sX/Lc0iEtHIJFq2gQHvhuqrWh1fntpJDXqCgeB9GYCmBiUoCuGD9DYQTWs1GIZqVEK +H8/zZuXc7QT2bJJwC58hrKhQaQO50HKmHLTfCruKMBTPicDCM+v5rZVdzP9hlUurJ ltDmALkRK6195eRWfVIl7Qp1GyUvvq3col/1FZAH89YeT68cGF/38NA4NcO0Ip0iVT MOLh0QyOt5FJw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4BAE26A0BA for ; Mon, 16 Mar 2026 12:31:30 -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 AL8WMpWeNQ6n for ; Mon, 16 Mar 2026 12:31:30 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685888; bh=rLil9DMUxyJ9cusWpTdgPBTruIMJUW11PbCSQwuO4OY=; 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=qqvJ9CAnF0rkbxb9gECKUqA4jh5B39TwH4f/C/RVcDX0sl3R9bSGozERTuPbJXFhk eGqAVFAbW9DJqlNtqZAcoPY26I1mJtOvgHTKzrSTfpe+HkZFeqI7Gjm0wGqusZ157H qJ6siDLdfz2syo2maON5HXr/47dENdUGehbEFbkgSsKeCvPaDopUsYWpU+ZWdObMwh FvnZ7JY0GkC6GLofJf7mJaJh8csIgSGxzAO0/WXtGvvjshxMZZTuueAPJrBCLq+f3x +Utsrc65VP2UaRBddKxApWjm1h2d9puNRLpBbxZ80ZRnIEp4VCyT1h8ytvwTgVMESD ZETV29lYSMbqw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 204AC6A0A9 for ; Mon, 16 Mar 2026 12:31:28 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685882; bh=2RTD6bcaV0zY01kYLc5G5bIrT8ughiP7MqdOHy6l8d0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Oc4ytIW2kbzlyVu2WEBU+dePGPH5AnF7AVZdR9EhtSjJDqPg07AWZ4jkqXOfR/yNj P934VuWBx+crSAX45nMqsZ0XWjUu+7brPRNSOdtrS/iaBwAmAseH4EIO4HRD+NDKdd pn+sOa3uH4yqzIG1bamyeMZ2tzi9aZv71CebsTAsu6fEM6tDYHQllm33+QXvk4kCI9 onwA7/8/iUcWhZVkRORMv7vpAs+bbaPkhckGm39mH5lsspMWsFZNafW7ofuBBhk0qg wp/whIiDgwhZEybBCv43Et4lZ9q3VLuaeQ5L/YGTMjRXGYI5ghWf4Nf3o2vou7jaup GwtQ660ewwrSg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8C2C56A0A5; Mon, 16 Mar 2026 12:31:22 -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 XwcfCBodsSiA; Mon, 16 Mar 2026 12:31:22 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685881; bh=HfNaFp0NoIrcFpu+ZN5BmQJW5NfkaRqNKcsvixXNqJw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e+SSW0xy/Wxi4ldrk6ur24ESrhNl1TcwdlF29cRPj1TSqiAk6C9tLHQTbewBUevfS GsYp23O4f5UnVmxol2GpsVMXtWiPYSrvvERtXTzOOlQrldJa8JdI7UzQlSPAJnfiGS +ANFV6bHtrOyCHvUMkMeZRFo6q/S35qNkbY50ncVniOT6221Ib8sHppaUHj4zGO59h X5q/VtN+MvH7a4diqpe7Vnx56B4EXDWZ4orn1AEIq7phI2T8AkGIl8fBqgFrglkf6T pDhLRyGdZYe15C+rwUv3ASUgX9zl8rQPXrLufvlB5jCdk/gYyiHlL8mTT/ztHVn1OO SXD68QvXbWNaQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id CFAD86A081; Mon, 16 Mar 2026 12:31:20 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 12:30:34 -0600 Message-ID: <20260316183050.3855921-12-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316183050.3855921-1-sjg@u-boot.org> References: <20260316183050.3855921-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: UQVVJW6A3IU37GQBTDGVSME77ICUWYQ3 X-Message-ID-Hash: UQVVJW6A3IU37GQBTDGVSME77ICUWYQ3 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 11/17] firmware: scmi: Fix memory leak in protocol list discovery 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 output buffer allocated in scmi_base_discover_list_protocols_int() is freed on the error path but not on the success path. Add the missing free(out) before returning on success. Fixes: ec8727b7e1c1 ("firmware: scmi: implement SCMI base protocol") Signed-off-by: Simon Glass --- drivers/firmware/scmi/base.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/firmware/scmi/base.c b/drivers/firmware/scmi/base.c index 78ee2ffd2da..d591b23d158 100644 --- a/drivers/firmware/scmi/base.c +++ b/drivers/firmware/scmi/base.c @@ -304,6 +304,7 @@ static int scmi_base_discover_list_protocols_int(struct udevice *dev, } while (cur < num_protocols); *protocols = buf; + free(out); return num_protocols; err: From patchwork Mon Mar 16 18:30:35 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2023 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=1773685890; bh=rXFU1gLR/wLZss0wLUAA3I8cg4H5KIK0CZubq5I3r/k=; 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=Jnv094XbG3Lsm2WijWuvnGw+IHxqmG0x8COk76ujF0hBp+z5deIa9aeKobI6CCFuG MEAhSNc3wJKsGA/9utHW22llsnsJqkw739aJDKa8im6HQFTHF4Fz90pX1bsySw2ugf kEEATBPdFAr8BKLcfJvrjeWJlazatdyQmSqvsO2yyU6I/wz1QLyOz9hWolbxIPc61t +WKnGVtUvD/AxJjIVYCv/1yEugi08wdVbSxqlusp/BSF7rptECohwgfTgRg/khTktP 6oXq0iYHDC7XGWzEjlKbm269nHC7PqeR6YPE4HQLG+7zwUp/yF4if5vcVRW4QPKTNo OdF3iChki9B5A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DFAC86A09F for ; Mon, 16 Mar 2026 12:31:30 -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 xjvHzf979ycD for ; Mon, 16 Mar 2026 12:31:30 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685889; bh=rXFU1gLR/wLZss0wLUAA3I8cg4H5KIK0CZubq5I3r/k=; 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=IaS5Zo2CYneJvXQAQnQZGF6DnSqkT+aZRyV7DALONxYuNsNjPDhZu8ueM1f8Rs8Rc rddnjIhewFg6312QPtIzc5EFnFgpPX30O815qgreXgukrbsQoFSLPBaEK0wyr4s5VD PgSVqYvYhWD3m1Skgn2isdL0uQWyg8TkOSjPsXoxtffMSgyw3ry701EyAksG2v9zXu zEVMSVEcmBzr8H8otpW7PNPrHuHI6wUpp2JlVbI4ny8uKEfHgKc2i9TEz6Y3N2sJWC gekBV418TCb5wT7wK4w8Y1m5/w+bz4WicU5Q4xHum8q9t5yhmatTnkYj103JswwpoD SksMqpm5ghBFg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 128A86A0C5 for ; Mon, 16 Mar 2026 12:31:29 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685882; bh=7xW69+YY5zTrDmJzqrV40+EMX3P0w7hwMTenXWvIDXk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qjt7cgcQ0hbOEZxHQoNfJV1O53r9ytzW7PBGsqP6AZKCwICG2oOpn63VqvTQEvhzK NDkzl4eiky49aUUJHowdPbqpumvbXLBUSwrUADNkNxsxPl9kpEHUIqXyFBtROXBmQ3 j3vNXXxWwWEv/J0F3vQSBaaRuR2tbmoVn2+ueUNcFI1YCyxWN9heNAAVdbli3qmUK5 0SK1kKmBJ2EKrqITnJv99HjfNcAJye8grnF1dv1lovX1UhIgg05HnN3UmGPpv5VLyQ JfiwPMQEHPvGx+L82F4a5TFJwyXEumOyrQjscvD+3orAkrkPYHkFoAkLR59iXAJ3BL mQ62Ln8DqXyPA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C75766A0A6; Mon, 16 Mar 2026 12:31:22 -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 MyOyYLKaJS-u; Mon, 16 Mar 2026 12:31:22 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685881; bh=0uspIHMqwyIHz7d/O4cB+zzgQg3slb1HeCFl2dxbIlI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=urFMGf91PZ0WCYszLhfmhYKDjSHBYNri83mOWloqqT8IRv+s5HyaMFcmL8v5iKAP7 BtOUTJmR5KkTUzvYSbf7UJnfAp6bETiQfQUmAXo5hQaXRn8sOwSP+ZzAe1xf1qlGSz cZowLmyVEh+jpCXvNgoSvnFnyT/Dvs/9Z8yTj56WwVG9wU1vq6tlwVT8CR7RTuXcBt e0Qf4vvc1Dgq5HINNzf0jM5FQH5l/26lB7omgQlJ91cHvc+CYXbuHZCtM9x0o+YP1a 20CJOs9azTr+tcOhxh3lXIqO0fCmDIUKhqX1jXBr253kDGn+OfewGCBYIB5DfH7jL0 xZQNbhpeY02Ig== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 89A576A07B; Mon, 16 Mar 2026 12:31:21 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 12:30:35 -0600 Message-ID: <20260316183050.3855921-13-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316183050.3855921-1-sjg@u-boot.org> References: <20260316183050.3855921-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: KXSRZ7WN2XMJZJCQ5Q7BGK6PBHOJTTKM X-Message-ID-Hash: KXSRZ7WN2XMJZJCQ5Q7BGK6PBHOJTTKM 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/17] power: pmic: Fix register leak in I2C PMIC emulator 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 sandbox I2C PMIC emulator allocates a register buffer in its probe function but has no remove function to free it. Add a remove handler to free the buffer when the device is removed. Fixes: eb7387ae14ef ("sandbox: pmic: Correct i2c pmic emulator platdata method") Signed-off-by: Simon Glass --- drivers/power/pmic/i2c_pmic_emul.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/power/pmic/i2c_pmic_emul.c b/drivers/power/pmic/i2c_pmic_emul.c index 6e81b9c3427..dd0ec39ef48 100644 --- a/drivers/power/pmic/i2c_pmic_emul.c +++ b/drivers/power/pmic/i2c_pmic_emul.c @@ -146,6 +146,16 @@ static int sandbox_i2c_pmic_probe(struct udevice *emul) return 0; } +static int sandbox_i2c_pmic_remove(struct udevice *emul) +{ + struct sandbox_i2c_pmic_plat_data *plat = dev_get_plat(emul); + + free(plat->reg); + plat->reg = NULL; + + return 0; +} + struct dm_i2c_ops sandbox_i2c_pmic_emul_ops = { .xfer = sandbox_i2c_pmic_xfer, }; @@ -161,6 +171,7 @@ U_BOOT_DRIVER(sandbox_i2c_pmic_emul) = { .of_match = sandbox_i2c_pmic_ids, .of_to_plat = sandbox_i2c_pmic_of_to_plat, .probe = sandbox_i2c_pmic_probe, + .remove = sandbox_i2c_pmic_remove, .plat_auto = sizeof(struct sandbox_i2c_pmic_plat_data), .ops = &sandbox_i2c_pmic_emul_ops, }; From patchwork Mon Mar 16 18:30:36 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2024 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=1773685893; bh=sDhhst1FdrBTGV7erl3jKLnjEK+CdeA6KjWV+88EKhU=; 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=cfuPm0EhOPg7W0OOTZx4awjEwt/CzqZMOXyFa5KfyJu5SbyIq92dv+oFExdyHmo68 /M1XfHXtj4Aq4LwLosRP855WU1tO5ADOVdypp3zsuUW27NnKNkjumLjl2bCGzE5yGv DujuXhTHrJm2ZP0zAhioHkiA93p7AoJKoS9xZ+1Aam74A6KgwxsXzUxaPfurqFoNAk CqzaA3UxCWLmuxct5vgjwAFLLL77d2RY2l51xKwwm7HI8YwniqdioukDF3ogEQtCFT oERJG0x3lrCznDBdq47jxoGZNMQ1rSVhKaJlL1eEl/DL3jiJMKw2jMZW+H5kvddHA0 IEbLc8IVjL/ew== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5DB2F6A078 for ; Mon, 16 Mar 2026 12:31:33 -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 VyIPbD61u6Bl for ; Mon, 16 Mar 2026 12:31:33 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685892; bh=sDhhst1FdrBTGV7erl3jKLnjEK+CdeA6KjWV+88EKhU=; 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=N37BbzrYSAyIBlAprNc8/bKu3XqzChMFyqM9LxTx4SolnqlbBiiaUBUsuhhCmMuv6 iNq1Fb84/nDFV8aq+HIHJX5oh9HnkLyjLVSBKJpQv9FrDvX2U8sQGT2iqDH7MWi65D IN2iAdxCifUaPle8sFJ2Ia61NP96QnjyuFZzssRiixSUdfyAIIslFnhFIgs5CEAnEv yGNvDI15BQ3cUPwrma/xMdDEvscluP4CZ3JxtqAdFGoUFo9F+HXnhTYWrsrdNrECmP /WE8HJji/klR86j52pkOb76rie9uZO3sDKuzDtpeHRKtRRFyi4hLtlCqMqhNhKg8GW VBuDAtcSrWX+g== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BFBF06A081 for ; Mon, 16 Mar 2026 12:31:32 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685889; bh=+toaxAu+imt7EnMNx3zmx1rzMJzLp8Dixi19D9OxiZA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=klhb/kkwoe3xz3WnXUQlo0QtZqTurz03lQpkBLD3U59p8m4UGG1ni70uftHJd1DCv SYnKHJZYNYwuBFbqGjNP96EiuPcnML2/S6m1aj+zC6g2DfnS1l3d2z5uNZx+OmpTgL Fde9c0rXlvPRMk+sGtKbsPHpn2AZ6K7VO1o/B0+YopI/i5Fe6JbGiQLG4DgFmcM5Qp Jz/EFu6wT3y35M3GpLAo/130VQ8pbJ2SjMxQzyqaDo++qN3vxmuYMKZzHHJUGS2w6B yeyq4VhcKCnToVfPBTgOf1ycZbuVivzYEYmDeVl04htR5DUSYJvIgFiIIggWRHCW/2 sGQkFMC1x4fTQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C61256A0B3; Mon, 16 Mar 2026 12:31:29 -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 AZkpflF5f7Ct; Mon, 16 Mar 2026 12:31:29 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685882; bh=TIXxihfJOf7VTTmhZGgdlvnGUaOPPIJ+vDNtDL8ErnY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QuADuKVHkDcmU3LcKIeGLyLkIClYk+3PSNzhYFi9rWopjjZsBNpWYIWESYhvkRCis 3ujKAZKIyPiTJSAlsOl16YMhoeCykIDGJDZxKS3JfeUEh+UyoHtNLxOjsLxibho2OC ENdD6d0xxAuc6b7Avb395p+sNyOcsa7Wvzq3UdI51gz1naitnIGdfCE6BGQq2tbjJf ivr0f6uj9lHjtVg+tK/D84bPMBvlqBRphKyUecfzB9qmtn+/wpylnmZqnYla5eXGY7 wkKR/nMoD7aTmslsfy/woUcM1LcpfrUmau0qtuW2QNUjlcxumkSXUUzwAl+ehOYFAs HhAfOqhIM2rWg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 6BC9E6A09E; Mon, 16 Mar 2026 12:31:22 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 12:30:36 -0600 Message-ID: <20260316183050.3855921-14-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316183050.3855921-1-sjg@u-boot.org> References: <20260316183050.3855921-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 3KXLSJ73JHJJUJXW4KTNCIIVXEIHMTAV X-Message-ID-Hash: 3KXLSJ73JHJJUJXW4KTNCIIVXEIHMTAV 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 13/17] mtd: spi: Fix device name leak in sandbox SPI flash emulator 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 sandbox_sf_bind_emul() allocates a device name with strdup() but does not mark it with DM_FLAG_NAME_ALLOCED, so device_unbind() never frees it. Add the missing device_set_name_alloced() call. Fixes: b6c2956defb4 ("dm: sf: sandbox: Convert SPI flash driver to driver model") Signed-off-by: Simon Glass --- drivers/mtd/spi/sandbox.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/mtd/spi/sandbox.c b/drivers/mtd/spi/sandbox.c index 0b56312bb85..573ce463294 100644 --- a/drivers/mtd/spi/sandbox.c +++ b/drivers/mtd/spi/sandbox.c @@ -553,6 +553,7 @@ int sandbox_sf_bind_emul(struct sandbox_state *state, int busnum, int cs, spec, ret); return ret; } + device_set_name_alloced(emul); state->spi[busnum][cs].emul = emul; return 0; From patchwork Mon Mar 16 18:30:37 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2025 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=1773685893; bh=Pom+VkAuDGqc8465EJICb0T0YPXdH/rkadv0bH/EZk0=; 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=UW1RXKDXZi9wby3IUSyaUmzEtFO0h/tUEWpyv5MCLu/UupE4BRHAcerdzCq4tnhVQ XeNUsYJKIhx1/2mByIYfTUAQrrIiYDsJ96C+e4a8Qw+7qfI1MfkSmrbBRhBEb6HjSg ZyNEslnickrVqwYniOt4iGu+qxJyNFsmWHa7JV+HZrnhLkpuJlTzrt1OYSzQryUPr+ SE/G/NaUGDgSHSuvCZORp1Y9dofVFegitXHUjU5eXPhKDyrX35FDMhER/pNsHZx5A7 v0l6iER6NhmrFNBO3hg1zeAs4Xmln03h+G+ftwL3PeYayseAVFjubPAOgHwcAlRktX K62WJoU4gv8Kg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AF6666A0AB for ; Mon, 16 Mar 2026 12:31:33 -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 WvJWVtLh8DVu for ; Mon, 16 Mar 2026 12:31:33 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685893; bh=Pom+VkAuDGqc8465EJICb0T0YPXdH/rkadv0bH/EZk0=; 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=UW1RXKDXZi9wby3IUSyaUmzEtFO0h/tUEWpyv5MCLu/UupE4BRHAcerdzCq4tnhVQ XeNUsYJKIhx1/2mByIYfTUAQrrIiYDsJ96C+e4a8Qw+7qfI1MfkSmrbBRhBEb6HjSg ZyNEslnickrVqwYniOt4iGu+qxJyNFsmWHa7JV+HZrnhLkpuJlTzrt1OYSzQryUPr+ SE/G/NaUGDgSHSuvCZORp1Y9dofVFegitXHUjU5eXPhKDyrX35FDMhER/pNsHZx5A7 v0l6iER6NhmrFNBO3hg1zeAs4Xmln03h+G+ftwL3PeYayseAVFjubPAOgHwcAlRktX K62WJoU4gv8Kg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 489366A0A5 for ; Mon, 16 Mar 2026 12:31:33 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685889; bh=pOeABCh/lMVj7ZIFVlpy9eNXukJsEY16cr8CrPy+A4Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S4knwDiNCXJeQ/hxFqVKtOnrhnj9o2enctEB3fkN2mHjEvwxkH7N0Qk0SaNepFke5 JghZWwl1ez3MCBGosT3pgJNTQ500SepIm6dSq9JIoDEgmM4DQ3DVrrBttKf6KceuEm p42VhN6RMIaqxigqlPXnySw3+cE5kuHWvhpUADe5zot/HrRPbA1f+u+pQapDXwKNuq Wfo1FLAwwi5+QxmBOE6Ho3DQsOaA2vmdiN0NGQGIQPOEPSoqFByZvFjerijngN3zep KtOHg7lKUyTwT0ic8wtaQLunMxRhD15hMO8X1g/a/Q+yseIq/Bvk9Y1q+qB3/dXkCT eXazPxhBcVSdg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CEDE66A09E; Mon, 16 Mar 2026 12:31:29 -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 iorScMAfoY7s; Mon, 16 Mar 2026 12:31:29 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685887; bh=4gnKBr7YPqHupZmXsM1yQJygHosO2R2QlTUOxQFe5ho=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tc4FeTAeaD8Fiu7IQGBzgvNT7yXVxh1Kfg4Gz+KWanun6ELuClMO07B53v5sqidwA d2+9V7o8ViKjUNncbdFNK6UxzcCHbk8Ww1LiiLesZ/MCSV0+2yk3Y1q6/U+4RUHVlC elGKdA1pcL36Sy+8qPwJD93aSW7uvYSzvrfmdiLZahVGyYcgdPOl+GBItLCI37yScb hune7TbL8eXMXDKz/2v9FJ7YRPDKP8hRJ409+cnbMTYVSPMqs9lBRYp1kwPpjjq+er jUX3BqV6IMHzyH89STFoRSncLI/LvUQdvYILQTkJPgtK5hRsQMA8UeOYpsJQK7L0WN kQ2Li8iFAcEiA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id EA7A46A07B; Mon, 16 Mar 2026 12:31:26 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 12:30:37 -0600 Message-ID: <20260316183050.3855921-15-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316183050.3855921-1-sjg@u-boot.org> References: <20260316183050.3855921-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 7ZNS75DUOVWIQKD4Z3WQSJNUAYKYLRUV X-Message-ID-Hash: 7ZNS75DUOVWIQKD4Z3WQSJNUAYKYLRUV 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 14/17] pci: Fix PCI regions array leak on device removal 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 decode_regions() allocates hose->regions in pci_uclass_pre_probe() but the array is never freed when the PCI bus device is removed. Add a pre_remove() handler to free it. Fixes: e002474158d1 ("pci: pci-uclass: Dynamically allocate the PCI regions") Signed-off-by: Simon Glass --- drivers/pci/pci-uclass.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index c370f8c6400..27bc92f0e4c 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -1874,6 +1874,16 @@ int pci_sriov_get_totalvfs(struct udevice *pdev) } #endif /* SRIOV */ +static int pci_uclass_pre_remove(struct udevice *bus) +{ + struct pci_controller *hose = dev_get_uclass_priv(bus); + + free(hose->regions); + hose->regions = NULL; + + return 0; +} + UCLASS_DRIVER(pci) = { .id = UCLASS_PCI, .name = "pci", @@ -1881,6 +1891,7 @@ UCLASS_DRIVER(pci) = { .post_bind = dm_scan_fdt_dev, .pre_probe = pci_uclass_pre_probe, .post_probe = pci_uclass_post_probe, + .pre_remove = pci_uclass_pre_remove, .child_post_bind = pci_uclass_child_post_bind, .per_device_auto = sizeof(struct pci_controller), .per_child_plat_auto = sizeof(struct pci_child_plat), From patchwork Mon Mar 16 18:30:38 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2026 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=1773685896; bh=mVqdE7vdhPxv0h46t4gvne19/xEPFPubSe8903uyqos=; 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=HIGqZRMjYPEqJ6yxGXyTi1fJvKqvBBfiWNCLacMqqUSfrDIiDLRiRKVAmArfUVA/f qkOURwYZqLmmReFVVcR0RGH4Vy3mNpgdRHT50DapzuuJ2mTlO40Lt7nJRP277++jQW tLcleeZ05I4UpaoUCoWk1vdRyhOqR4iQhos7bI/S6M8TREvX1ibsFZPiFmpzxKvt4K ZAJ99mJn0pC+q6GbmnSb/5jzh4KS/RPWzcfDBFd6DYeEr6WkbdrAB+TdA+CTJ6aSe2 3QeApiLduzW8pTpb4ALjDytK7QM84rurDH8iIn4a5UwE8qt9DZeq6tRVmja3i0znl/ z3WDd/yszI3VA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4A3766A078 for ; Mon, 16 Mar 2026 12:31:36 -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 6ciTf6yOHBa1 for ; Mon, 16 Mar 2026 12:31:36 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685896; bh=mVqdE7vdhPxv0h46t4gvne19/xEPFPubSe8903uyqos=; 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=HIGqZRMjYPEqJ6yxGXyTi1fJvKqvBBfiWNCLacMqqUSfrDIiDLRiRKVAmArfUVA/f qkOURwYZqLmmReFVVcR0RGH4Vy3mNpgdRHT50DapzuuJ2mTlO40Lt7nJRP277++jQW tLcleeZ05I4UpaoUCoWk1vdRyhOqR4iQhos7bI/S6M8TREvX1ibsFZPiFmpzxKvt4K ZAJ99mJn0pC+q6GbmnSb/5jzh4KS/RPWzcfDBFd6DYeEr6WkbdrAB+TdA+CTJ6aSe2 3QeApiLduzW8pTpb4ALjDytK7QM84rurDH8iIn4a5UwE8qt9DZeq6tRVmja3i0znl/ z3WDd/yszI3VA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 004446A07B for ; Mon, 16 Mar 2026 12:31:35 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685893; bh=tjlnbcDIgN1lGpa8JCS1oAOK/uAjC98nK4yWCGqu97c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nDcxmicOmZjq5XXKeXEJZGMYauhK8Y4vAzOHbBtSTbfKXYW0T3GQ2Wu6bY2p615ty A9tKqVhfCXay0JjVhxljCUW/XZcLosF7/TMWM1ye5BUmjOf1N2DUqNJJBol7ppWWC9 EAkGM/nynvQ30U7hn4GanXTb4CdCzX6R6RNdELv2xVO0AS052bTgVUdDmg/JPnDaNk 934IhjafZ+DFIwCETzbLKNYHWb3ra9bGAZWpY+O+HXk2WHz88U+P/zNMBxGoeIIdqU 5WcuGa9CnwokWp7BgA3s0UjHgvv1gJpjwMNNgWPe84axP/DRA5Ub8P7xoz7wOq9/Zw cThSCk0C/fepg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 42B2B6A0AC; Mon, 16 Mar 2026 12:31:33 -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 5Tux16NVOBbO; Mon, 16 Mar 2026 12:31:33 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685887; bh=q9kabSq7jezyMcxURkwvQY++hND2VxaOGPuEaIjvj8c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F2YRMXa1t1gFw0wCKFhP6/wXfZp/0P+/Zn4sPMwqJ5E2F3PiY7P9v/jeiIPFpy+eT h4tmtXqbnenXY/JW20MXr1mfchBHEABuBVupFgYcFnk21ZElYAm53VNN9vmZkdl6nM ozjoUuA91+rqQ8UPKTG7D5o+OJCry6tsgXeIaPGI4ic0gZYIdHw1QCLZoQeEG/HBQs l8EJR4YuDZzz2Z19KifUijPDFVKjmeSMWuFon55x9ixLS3Z5cK1eys+VRw+TOHQYBU VMI8BqeH2iB+Ajdi9SP2vp4X2w4Wyh1fhBJboXRkNYRwKRaHGVXgp7cXklvH4JxB8x w3arRgccFqNkg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id B092A6A0A5; Mon, 16 Mar 2026 12:31:27 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 12:30:38 -0600 Message-ID: <20260316183050.3855921-16-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316183050.3855921-1-sjg@u-boot.org> References: <20260316183050.3855921-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: CTCPPCSS42YX75FBJXTL47FW3MW4WXHV X-Message-ID-Hash: CTCPPCSS42YX75FBJXTL47FW3MW4WXHV 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 15/17] test: dm: Fix memory leaks in ACPI DP tests 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 Fix three memory leaks in the ACPI device property tests: - free_context() does not free ctx->base, unlike the version in acpigen.c - dm_test_acpi_dp_gpio() does not call free_context() - dm_test_acpi_dp_copy() does not call free_context() Fixes: 0e5a0a00d6e4 ("acpi: Support writing Device Properties objects via _DSD") Signed-off-by: Simon Glass --- test/dm/acpi_dp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/dm/acpi_dp.c b/test/dm/acpi_dp.c index 038806004b5..90921329556 100644 --- a/test/dm/acpi_dp.c +++ b/test/dm/acpi_dp.c @@ -36,6 +36,7 @@ static int alloc_context(struct acpi_ctx **ctxp) static void free_context(struct acpi_ctx **ctxp) { + free((*ctxp)->base); free(*ctxp); *ctxp = NULL; } @@ -419,6 +420,8 @@ static int dm_test_acpi_dp_gpio(struct unit_test_state *uts) ut_asserteq(ZERO_OP, pptr[0x1b]); ut_asserteq(ONE_OP, pptr[0x1c]); + free_context(&ctx); + return 0; } DM_TEST(dm_test_acpi_dp_gpio, 0); @@ -486,6 +489,8 @@ static int dm_test_acpi_dp_copy(struct unit_test_state *uts) ut_asserteq(STRING_PREFIX, ptr[0x8e]); ut_asserteq_str("sunrise ohoka", (char *)(ptr + 0x8f)); + free_context(&ctx); + return 0; } DM_TEST(dm_test_acpi_dp_copy, UTF_SCAN_PDATA | UTF_SCAN_FDT); From patchwork Mon Mar 16 18:30:39 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2027 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=1773685898; bh=NH241/yv/aH9izj5C+S/2aP+CIzNcuPNcXlnmgclU2Q=; 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=Uv/gGvHDLAR2G2mjqPZokxoLNLcBR9OmFmQG3DGcAcx58akzgirsKjQHbRVn53VAB fWuEkQ3mp4SFjewbEYAYqu7Y2zIkfClz5tfoMgNs9MQfjmYej5A+nIv0iy0n9bY23Y eH1qy2DnUFQ9fPyxArfLNUHoaouJpxUqOHyUkSaovlNSJ0w9DHQInV3JSJDuy2MSB+ oz+qf6Rp+sWUu2DXtGQ86nbCfuZqK4Co5dpvOyDDoZwmFTJdz0C1/PR/LeUu6uq8OU a7vdRxe3kT7/0pMqZ5cOm/HF1Y8056Pn7UU6aaXO2FkS5e+kscMmbShB9d+rdag5U3 n3oS6byiEBsRg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E48966A0B5 for ; Mon, 16 Mar 2026 12:31:38 -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 4emFumhjUYOA for ; Mon, 16 Mar 2026 12:31:38 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685896; bh=NH241/yv/aH9izj5C+S/2aP+CIzNcuPNcXlnmgclU2Q=; 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=sId6F4TRI/rbDT5/Z6mfwYIbVPTNQz6G8BKKTSmiNdu44Tp5GD4BRMZcjLWxTjgFB hD6VhCsMMbz0MzeksbAVBsilc0bALP9MzwgK7dQQHOz6+ZtOtDV/wfq5Cy1KIYRbpu OOtmosk3QGefcV1+yJ0lRQOKUBIfIu8mExoF7a1omVQ7UVGgG3FigilqVCYVcqku/2 ZvTBPbI0MewwTNaSyTk/lNSbJc6XbBGapkzl1nSLevHBajBp4L1MYwVPiDIPu2JnHa iQbll8FOtTsC9Lpb0plnhjdpD24lblqW6jVlSFvR8JpHz6DUICB96VBDDLJq+l65X8 skCl4E/aFvnKA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id EC2CA6A07B for ; Mon, 16 Mar 2026 12:31:36 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685893; bh=GfoNXD5byq60iOwVAcqIF/eZPIeQMJlSck1jeloJqmE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lEYpSgVHBj7vq66D6Jm0Jk06yQjcuOFTG94fVfw58PfXDs5xV4GwAPAevWaLjBCNv /wHfV5L+VzNTm/4XYTdvZkljoa2e2x3P3tYvMcv8iH8Xk8prISGIlwkxpMcfklHvOs Pf/rIDDlvDAli5N1FvmWQzQ1PxlJ0PdxwOcOo8qNCwKPCwlNoYtnk4dGXvX7u9Hgv4 8O9NGRDoRbK5HxPqXGfvXmqWDjwSpy0BZA+b4I/hopEzTfxG8QSgT9FEY4/7eHBwk/ PADg4/XNWUMH6xNo27GV0BIv36umtrxQijxyykKMB8vftqh933dNt0bWiVr+L1A+/1 0iRd1Q13Y806w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4B97C6A0AD; Mon, 16 Mar 2026 12:31:33 -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 QxPWMFN33uQP; Mon, 16 Mar 2026 12:31:33 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685892; bh=s8lg1JeEUlxme67Jk9WNywhY1L70H7U6ZXKLe5W4Ddw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H7HwBEOxu9Hnp2dWJf9nSK7ANCemiAM/kvUH6JlDCOPC7aBEur7e5Rbh7o725WQij COoJLEqPkb8X5jg8mNSZp7hCdudnPiZM8AMSgp583VyigZVHhw4rYkroTPF5csAwTE ofIixZoe1uTUxoZSdEdVBzieHSOizfg1oIa6PNd408cDplgnicXd8En2574XKvxq8f NP4svGZvI935i9P6PvfkSIcfuPv9bhRVglGLjiF5/dAyFCa3sWHgf05hqDfvxkX2Mn LQBfuZXb9XWeVuhjFxS/WAHVOrqf0HotNoV58jfCkXcD6udoNTeiaAhbYVI6cKYXXb rHRG6Kr3j6I9w== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 34CDE6A07B; Mon, 16 Mar 2026 12:31:32 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 12:30:39 -0600 Message-ID: <20260316183050.3855921-17-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316183050.3855921-1-sjg@u-boot.org> References: <20260316183050.3855921-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: RYTCAB3DIA6MDQ6KI2VOLMHVV2K7NRRH X-Message-ID-Hash: RYTCAB3DIA6MDQ6KI2VOLMHVV2K7NRRH 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 16/17] dm: acpi: Fix memory leaks in ACPI item tracking and tests 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 acpi_reset_items() resets the item count without freeing the buffers allocated by add_item(). Free them before resetting. Also add missing free(buf) calls in dm_test_acpi_fill_ssdt(), dm_test_acpi_fill_madt() and dm_test_acpi_inject_dsdt() which allocate a buffer with malloc() but never free it. Fixes: 18434aec1b69 ("acpi: Don't reset the tables with every new generation") Signed-off-by: Simon Glass --- drivers/core/acpi.c | 6 ++++++ test/dm/acpi.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c index 4763963914b..efb935ed6a1 100644 --- a/drivers/core/acpi.c +++ b/drivers/core/acpi.c @@ -377,6 +377,12 @@ int acpi_inject_dsdt(struct acpi_ctx *ctx) void acpi_reset_items(void) { + int i; + + for (i = 0; i < item_count; i++) { + free(acpi_item[i].buf); + acpi_item[i].buf = NULL; + } item_count = 0; } diff --git a/test/dm/acpi.c b/test/dm/acpi.c index 588a518bc4f..9eca5df967b 100644 --- a/test/dm/acpi.c +++ b/test/dm/acpi.c @@ -596,6 +596,8 @@ static int dm_test_acpi_fill_ssdt(struct unit_test_state *uts) ut_asserteq('z', buf[4]); + free(buf); + return 0; } DM_TEST(dm_test_acpi_fill_ssdt, UTF_SCAN_PDATA | UTF_SCAN_FDT); @@ -622,6 +624,8 @@ static int dm_test_acpi_fill_madt(struct unit_test_state *uts) ut_asserteq('z', buf[1]); + free(buf); + return 0; } @@ -654,6 +658,8 @@ static int dm_test_acpi_inject_dsdt(struct unit_test_state *uts) ut_asserteq('z', buf[4]); + free(buf); + return 0; } DM_TEST(dm_test_acpi_inject_dsdt, UTF_SCAN_PDATA | UTF_SCAN_FDT); From patchwork Mon Mar 16 18:30:40 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2028 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=1773685899; bh=smxRl2aq31hYmTV2UbLx/sFV7eL98jxfY1gApWj8y84=; 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=TSzDg8xV9u42P1gJABigJvucU3J7ntz5QzdhLF78UbwYRSyxsbeiLmhlwXcAFNJPT 668KriP2d7oVbNHWZyckNQGMXjQhPB2qnZjVQTdTOOyy/FNKnf1YSbnfYCbJsci3zF FUli4F/BdY5R6J+SP/JaHYPrCU+SqHV9yI/yV6f1XC+AJ7j2EdkZoLq+iIJ+VaaF2/ wxI+0ruQvNoD/sQCijfylnc4aFKhZBh1BKQXH/1/mpRWk9XSD37m9gage9K1QSVH5Y rEhgO+XyHCURfAZIG47G/OElGRurfg02Y36+tG2AGMP/KfeedPn7lq24r0PkCZAfEt dt8xNhRJuKnWg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 413266A0A5 for ; Mon, 16 Mar 2026 12:31:39 -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 DSMkImkRsfnv for ; Mon, 16 Mar 2026 12:31:39 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685898; bh=smxRl2aq31hYmTV2UbLx/sFV7eL98jxfY1gApWj8y84=; 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=Y2H5Ws84VrTOGb5v2++/uWB0D4KB7KCQ+RQdEt3kbo3iH6Jk7kOnHTRyx0318NUeo YS0ZViVfnP/sjUSQz1c/8NUZNiE2lnNZUTFDXJCjJGpnIuaqczGSd3j00ox1PF36k5 KB5Jp3keAPleS8iXz92FuU8+1921L+6RHwJ4rHWya5RxrtPq0rg6mmZQreDoGOi9Tl iOROiUtfkSLPRaXFqwDiN0v/JJJdIT/SJJ1lMCT3sQgPAVmpvsFjfgau6kHHEJo9ko Hh4LF69P8ja0GD3YIBd6xJ3lDSUcvlCz3SUUyyVDDC91iz98IyWSns3o20+4yXboot mT2RgG8eiGaIw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AA5906A09B for ; Mon, 16 Mar 2026 12:31:38 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685896; bh=QEXHtkeDCh6UAfgmVUIQcDTe0l5jQd7U7n97/GR/x2c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jsenmsw0YZL0CTMuCUHQyhBSKmQeGL9sMjE9QLmVJJRDAcXB3s9x6FlLdAUS0zceN EoviBMN5s+poZNfg8FpfMTg/WlLIc4GUVgv1R170BptFOdLrfb7G6kKOQGj1EJ8ZtL HghFBAcbC2ge/cPrm4g1KDIuyplVB1KfPPquddrCqOPH1daOiddNLm6DeVwI8F7003 5S6TN69srS0kIyyau3k4QlWhR9AToQAT2eEVpSxApS2dEuEZ5N2GKZX6lxAol+5uav OawcNsNJLSjTnAEV7HngkVdGaXGhFSjwsBaPxJ45HdRBGmz83sgfoHWXhYOkIfPLai rF5L/i7vDuMcw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 367156A081; Mon, 16 Mar 2026 12:31:36 -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 OSVhNitBVCs9; Mon, 16 Mar 2026 12:31:36 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685893; bh=qmGWhLXrNQvtTTu4ybe3VYpkBifRxSKIxuwZujq46XI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k+WxneF7B5F9pfPfNHPXrqWq5PwTPA+ENFW1vlm86AF9yRIK26TFSpnKUYx/zQSAO suwTEWb/zNwB8Y9pNx9kp58kgA0rg/O76mRm4I4ramFdxatvmYDcAvetBY/KijLJAV etbIeDKhyAR8N4YO3Jd5WOkAtQjWue11H2+38dHYCTrhFG+MaRi8UAXud2BpHH5rV3 ZFLRI+QVvrELGrWgjq5Wn6CBD8cH06KPVs38gFMt1orcKWTnYWzWOO5da5Lm9YZTJG nIia+cWhnWfBsLDRTLwi1rftAjQLXlFf3IuaStLDLowtIFk4a4e9+N6sQRRckEd9Nx wFurg0E2kjG8w== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id F27CA6A09E; Mon, 16 Mar 2026 12:31:32 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 12:30:40 -0600 Message-ID: <20260316183050.3855921-18-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316183050.3855921-1-sjg@u-boot.org> References: <20260316183050.3855921-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: D446THBMZWF2R6WCOJKXRGB5JOYDONXL X-Message-ID-Hash: D446THBMZWF2R6WCOJKXRGB5JOYDONXL 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 17/17] video: Fix map_to_sysmem() leak in show_splash() 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 show_splash() calls map_to_sysmem() to convert the splash image pointer to a physical address but never unmaps it, leaking a sandbox memory-mapping entry. Add the missing unmap_sysmem() call. Fixes: 84e63abfff67 ("video: Support showing the U-Boot logo") Signed-off-by: Simon Glass --- drivers/video/video-uclass.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c index b492ff313aa..20d98798520 100644 --- a/drivers/video/video-uclass.c +++ b/drivers/video/video-uclass.c @@ -661,6 +661,7 @@ static int show_splash(struct udevice *dev) data = video_image_getptr(u_boot); ret = video_bmp_display(dev, map_to_sysmem(data), -4, 4, true); + unmap_sysmem(data); return 0; }