From patchwork Thu Apr 16 02:29: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: 2166 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=1776306650; bh=p/TcOnkLtGpt9kOx0c/Iqc6UQ6OhNO0s34DpAffNWG4=; 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=Iy/qE04FE6NfuOChsaR2ObkbJUu2ZXd1SM7eJ6bg68erCosDytEs/oRKifY8K8O3a dRqCYLviQpQtw/g5pzo5Pmn23pHO/JCdMeK7P+o+7mEtQdhCarjWcVNSh97qzUKcfx qwyb5XzpQJ76dCc6uHz2DCFvrAXDdnBUQ6MUf4Yg= Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 924776A4B0 for ; Wed, 15 Apr 2026 20:30:50 -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 ebPLe8JLtiAP for ; Wed, 15 Apr 2026 20:30:50 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1776306649; bh=p/TcOnkLtGpt9kOx0c/Iqc6UQ6OhNO0s34DpAffNWG4=; 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=DkarP+Txd37/rz6CHoX2LQv4fTvQVTzgp+V2xkUMktsorU9nO3tthCYcQ+RVOnCYg GKfQcf+q5wphiUnCCh7jmYvrNdMeeurv4aKxRyXj3lubyIfb5Vy91oOn2zuivv20zi UM5pum/5BakaRcyTagvOMjOIddGyo23Xsvln6da4= Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 25AD76A4A8 for ; Wed, 15 Apr 2026 20:30:49 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1776306646; bh=mbtyLRNakAOityTu8o7rePEP8IestwzhAjP0Q7kHwoY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cj/18XCMYjVuTW0MO3/SyWqKApIkKxAlsatXsz7VnJq4bzsL4E4PkGHqqItXzTm7V k4Tm0uWqvdqQAdjCVUEx2fcG3rmRfI0WrubfoWIu3TceAp25RdyDEK7tO8ipPMZ/YI reneveVBauUoqt+DmA0MeYMHH1zLxJsPrZJnv+Rs= Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2E9826A49F; Wed, 15 Apr 2026 20:30:46 -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 pKIWXvzbMD80; Wed, 15 Apr 2026 20:30:46 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1776306645; bh=zbgaZUFr6zIPjdYwET08zfw8kydhpRz9Tp6BtTpCC7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ah8ZrxkWrJIQ+U1AtNyiltGIGY+igDI0m2URi2BThCwotS0AT+VGRqxDBUBFVevPq Faydk7YNfQhXN8Z1NTty0CxV4Mo/+ZU/ucniVEzAlSzbw5Ro13m6vdmRTzh3EZ+EUU feHGBiw9qWozEkEgkzAi/LPruf+Rifln8bO/fvj8= Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id A5CA76A44C; Wed, 15 Apr 2026 20:30:45 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Wed, 15 Apr 2026 20:29:28 -0600 Message-ID: <20260416023021.626949-4-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260416023021.626949-1-sjg@u-boot.org> References: <20260416023021.626949-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: JBZD5IK3FKR4TXJLDOEZLFMGZI2GS4Z6 X-Message-ID-Hash: JBZD5IK3FKR4TXJLDOEZLFMGZI2GS4Z6 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/33] malloc: Report mcheck-registry entry count 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 When tracking down heap-registry overflows it is useful to see how many entries are currently tracked, so the limit can be compared at a glance. Expose malloc_mcheck_count() as a public accessor over the existing mcheck_chunk_count variable, and print its value with the 'malloc info' command when CONFIG_MCHECK_HEAP_PROTECTION is enabled. Extend cmd_test_malloc_info() to check the extra line when the feature is on. Signed-off-by: Simon Glass --- cmd/malloc.c | 2 ++ common/dlmalloc.c | 5 +++++ include/malloc.h | 2 ++ test/cmd/malloc.c | 2 ++ 4 files changed, 11 insertions(+) diff --git a/cmd/malloc.c b/cmd/malloc.c index 6b019f4c056..7de421c0ae8 100644 --- a/cmd/malloc.c +++ b/cmd/malloc.c @@ -27,6 +27,8 @@ static int do_malloc_info(struct cmd_tbl *cmdtp, int flag, int argc, printf("malloc count = %lu\n", info.malloc_count); printf("free count = %lu\n", info.free_count); printf("realloc count = %lu\n", info.realloc_count); + if (IS_ENABLED(CONFIG_MCHECK_HEAP_PROTECTION)) + printf("mcheck count = %zu\n", malloc_mcheck_count()); return 0; } diff --git a/common/dlmalloc.c b/common/dlmalloc.c index ae1e6d27d08..895aa215228 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -6015,6 +6015,11 @@ bool malloc_mcheck_overflow(void) return mcheck_registry_full; } +size_t malloc_mcheck_count(void) +{ + return mcheck_chunk_count; +} + static const char *mcheck_caller(void) { #if CONFIG_IS_ENABLED(MCHECK_BACKTRACE) diff --git a/include/malloc.h b/include/malloc.h index 0a780fc03c3..787ec999f5e 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -875,8 +875,10 @@ static inline bool malloc_backtrace_is_active(bool *skipp, bool *busyp) */ #if CONFIG_IS_ENABLED(MCHECK_HEAP_PROTECTION) bool malloc_mcheck_overflow(void); +size_t malloc_mcheck_count(void); #else static inline bool malloc_mcheck_overflow(void) { return false; } +static inline size_t malloc_mcheck_count(void) { return 0; } #endif /** diff --git a/test/cmd/malloc.c b/test/cmd/malloc.c index db4350afe68..812f7530b79 100644 --- a/test/cmd/malloc.c +++ b/test/cmd/malloc.c @@ -28,6 +28,8 @@ static int cmd_test_malloc_info(struct unit_test_state *uts) ut_assert_nextlinen("malloc count = "); ut_assert_nextlinen("free count = "); ut_assert_nextlinen("realloc count = "); + if (IS_ENABLED(CONFIG_MCHECK_HEAP_PROTECTION)) + ut_assert_nextlinen("mcheck count = "); ut_assert_console_end(); return 0;