From patchwork Mon Mar 16 18:30:23 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 133 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=1773685869; bh=vrrCuBBW1CeReb/XI+hDbTGoIVrAv6LGBHFQfU3m7zk=; h=From:To:Date:CC:Subject:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=T+Hu/befKJ0xpr0HSUUgTBJs6O0u8VewukSPt8WDAEBkD1XqUFNNvBeaa2AzFkKfk 8xSP4qeKqmPvYm62it1nz53OfG7ejKaCHr/yNeVOQRnRAckvPjYzoA4TcppHIowBoz tz6Ve6gF0Qc0i19biLaQRZZD3KSL3bDx+TMYza7McIFMhMFJEVilD3ZW2KdQVFsIFw unkdiOwGkQwgq+rWv2hkqqZFHCH0sLlhl62fROmm520GFv9dQ6yshtkPEUtFgjAouy N5uxn++I2i3v19fSZH2H/NbRsUI2K8Oyxh3PKLODFR3tSeMGLp2qLwTAEcZIk/g0Qt zwpLRUsaiRimg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8D2476A09E for ; 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 10024) with ESMTP id O6_AZlcI-3tt for ; 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=1773685869; bh=vrrCuBBW1CeReb/XI+hDbTGoIVrAv6LGBHFQfU3m7zk=; h=From:To:Date:CC:Subject:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=T+Hu/befKJ0xpr0HSUUgTBJs6O0u8VewukSPt8WDAEBkD1XqUFNNvBeaa2AzFkKfk 8xSP4qeKqmPvYm62it1nz53OfG7ejKaCHr/yNeVOQRnRAckvPjYzoA4TcppHIowBoz tz6Ve6gF0Qc0i19biLaQRZZD3KSL3bDx+TMYza7McIFMhMFJEVilD3ZW2KdQVFsIFw unkdiOwGkQwgq+rWv2hkqqZFHCH0sLlhl62fROmm520GFv9dQ6yshtkPEUtFgjAouy N5uxn++I2i3v19fSZH2H/NbRsUI2K8Oyxh3PKLODFR3tSeMGLp2qLwTAEcZIk/g0Qt zwpLRUsaiRimg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7B9006A08D for ; 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=1773685867; bh=Iub+m1G7wG5KTjVBvSHr5h7pQPbz3AqFWz1QIbMkB/E=; h=From:To:Cc:Subject:Date:From; b=Hp9nSFIcShSlJcXMeM9t6HjH/LMaDwHyPV70r9SooN5IzZvese/RTb673xzJy3K4I 0ybBqLvGjLV+eMbkLoVz6CyZVoga3PXCYGAEy6JFJHn27S1a4dIL2Eq5kdKH8I2swo DM9WkIkx3vbvEqVq9LaTn3BUISCiiQfdYvvO4Qxig8UN1K8WxoCwzeVz/Sg4TeHC74 uh+8mYcMUJwjq0LcedgFDobz4MxALF2VRsbVJ3YyLHvEtCoAUWljiCxnlxD+/cnacE 6cNaIoeFrbkSUGAsKiWDQ+ZFF9ipero/V35h/11kV0JXhHvdeD2meHpogWsTDOcC/A /UNhCJV48imww== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4E1036A07B; Mon, 16 Mar 2026 12:31:07 -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 SGcJxOZXxKju; Mon, 16 Mar 2026 12:31:07 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685864; bh=O+xIvlV9cWaEASB88qyUGRAPBPFNJ3JePTViei/LS1w=; h=From:To:Cc:Subject:Date:From; b=YPUDI7vk3Rl+8NJx11pglIKJH8f2fszvxZ/7jxLtoTVgAl14xJ9ej8GyWCRQk9in+ mF27FVr0CIp+6SMF40IlrTMddvDUWfelDEJSRLaKgF8HScnhPyrQrV/RwYlzTzCDiO cPIUXBOjhDwQw6qybD9aZP8Dma2UkOabOcP0M+apm+WjHAh7ukzhwfN4Kplv/K91rb jMq84d8sdodwZ8FDvKE8W3lnxxwhDjM+KW43l6EacJsQQFsoGs8PLR3Wiwb6Jgw4u9 +cMN00Y4J5J4A6gYLvG6sq5x5qvcMt/DWqvfzLB41EVlp65orqLbmCbDhEdGUxPBdB KZB9fbfBlxc5A== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 69D976A078; Mon, 16 Mar 2026 12:31:04 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 12:30:23 -0600 Message-ID: <20260316183050.3855921-1-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Message-ID-Hash: TLBL3AX6XBGBXJNW3MGRC2HMRNVFK5TI X-Message-ID-Hash: TLBL3AX6XBGBXJNW3MGRC2HMRNVFK5TI 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 00/17] Add automatic memory-leak detection to U-Boot 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 This series adds built-in heap-leak detection that can be enabled with a single flag. It snapshots every in-use heap chunk before each test and reports any new allocations left behind afterwards, with full caller backtraces. Usage at the U-Boot command line: => ut -L dm dm_test_acpi_bgrt Test: acpi_bgrt: acpi.c Leak: 2 allocs 14a5c5c0 110 stdio_clone:230 <-vidconsole_post_probe:961 14a5c6d0 b0 map_to_sysmem:210 <-video_post_probe:823 Or via pytest: ./test/py/test.py -B sandbox --leak-check -k dm An interactive 'malloc leak' command is also provided for investigating leaks at the command line. The initial scan found 90 leaking test runs across 7 distinct bugs in SCMI, PMIC, SPI, PCI, ACPI and video subsystems, all fixed in this series. Simon Glass (17): kbuild: Use relative paths in generated .incbin directives blk: Return error from blk_get_devnum_by_uclass_idname() sandbox: Return -ENOMEM when os_map_file() fails vbe: Propagate probe errors from vbe_get_blk() malloc: Add heap-snapshot leak-checking functions test: Add memory leak checking option to ut command test: Show leaked allocations with ut -L test: Reset malloc backtrace collection before each test cmd: malloc: Add leak subcommand test: py: Add --leak-check option to pytest firmware: scmi: Fix memory leak in protocol list discovery power: pmic: Fix register leak in I2C PMIC emulator mtd: spi: Fix device name leak in sandbox SPI flash emulator pci: Fix PCI regions array leak on device removal test: dm: Fix memory leaks in ACPI DP tests dm: acpi: Fix memory leaks in ACPI item tracking and tests video: Fix map_to_sysmem() leak in show_splash() arch/sandbox/cpu/os.c | 2 +- boot/vbe_common.c | 11 +- cmd/Kconfig | 10 ++ cmd/blkmap.c | 8 +- cmd/malloc.c | 65 ++++++++ common/dlmalloc.c | 254 +++++++++++++++++++++++++++++ disk/part.c | 23 ++- doc/develop/malloc.rst | 68 +++++++- drivers/block/blk-uclass.c | 19 ++- drivers/block/blk_legacy.c | 3 +- drivers/core/acpi.c | 6 + drivers/firmware/scmi/base.c | 1 + drivers/mtd/spi/sandbox.c | 1 + drivers/pci/pci-uclass.c | 11 ++ drivers/power/pmic/i2c_pmic_emul.c | 11 ++ drivers/video/video-uclass.c | 1 + include/blk.h | 24 ++- include/malloc.h | 111 +++++++++++++ include/test/test.h | 2 + scripts/Makefile.lib | 11 +- test/boot/luks.c | 15 +- test/cmd/malloc.c | 52 ++++++ test/cmd_ut.c | 8 +- test/dm/acpi.c | 6 + test/dm/acpi_dp.c | 5 + test/py/conftest.py | 3 + test/py/tests/test_ut.py | 6 +- test/test-main.c | 24 +++ 28 files changed, 710 insertions(+), 51 deletions(-)