From patchwork Wed Dec 10 00:07:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 873 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=1765325357; bh=zBBD230c1QUQMRAoyCT0VNvl2hPgeui2YdRQb4W2Mfc=; 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=qamnnfwNhWEZU5+6NluTRmgcSAC0cxJYzxf3R2FIa7/ffUE84KwgZ32D4vCB2yMUr CfbtJByI9sKttOWXSQoP4R1SA69sStnJASe2ErN96a42b993kaDifB0PGp1yqr75ly Dxnbn58IrTmgy/6AM89YNl6UkC2y7jRuSqHeP9kHvJgxUBaaIQv4RcGQIMlhYv2BIe NNJ+51jGo64N7Z9/uluwEBJ3Gq/VvWcxf5cQpHfu9IqERjhC3CAysggGyqPtHb1qyM DsiHL6SAQAd76xN7GrJzKc7BMo3mW2O8lMcyv550MuieSUjmIYwM3aTOsR4PbF0V09 DhDTAKg1rXsUQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6661D68A22 for ; Tue, 9 Dec 2025 17:09:17 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 4UmiCnYZSPVG for ; Tue, 9 Dec 2025 17:09:17 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765325357; bh=zBBD230c1QUQMRAoyCT0VNvl2hPgeui2YdRQb4W2Mfc=; 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=qamnnfwNhWEZU5+6NluTRmgcSAC0cxJYzxf3R2FIa7/ffUE84KwgZ32D4vCB2yMUr CfbtJByI9sKttOWXSQoP4R1SA69sStnJASe2ErN96a42b993kaDifB0PGp1yqr75ly Dxnbn58IrTmgy/6AM89YNl6UkC2y7jRuSqHeP9kHvJgxUBaaIQv4RcGQIMlhYv2BIe NNJ+51jGo64N7Z9/uluwEBJ3Gq/VvWcxf5cQpHfu9IqERjhC3CAysggGyqPtHb1qyM DsiHL6SAQAd76xN7GrJzKc7BMo3mW2O8lMcyv550MuieSUjmIYwM3aTOsR4PbF0V09 DhDTAKg1rXsUQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 55E77689E6 for ; Tue, 9 Dec 2025 17:09:17 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765325355; bh=3//tW05RY83XIgtXdAQJuKYxlyuKLoOZDsonMuxcOCg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DYNi6ZC8qUjmLLLSMRvBYbrwHdnCZg6DzGlNI/3NnIC/m/eXi9iVVxeoTYPAxRzrV wW3VebtKd/Kpmbswwzab3tw8mu8PQ1PgI2mox3WxFndi2EeZxE7/gt+yjaivOc10St nbqBs/3OTy3o+/iie+i7gaoBTffMNeYKuxkOAeOYBKzMwpAtQff/epqdT83LVv1sta kR9jHpXg2uvnMSDU3EfbHGcDx184fZWNqNoUk0FWhNa0XhT6GVw7uqPD7dXbiZjw1J fYR6d/nA56XM0hwfnf2o6BmRle8UhKim9Vz87yb808Lm8Glhair1Kq1ytSNM+ehjEZ rhI3g7gEyNc4g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B888E687A7; Tue, 9 Dec 2025 17:09:15 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id MCIRmymgl3d1; Tue, 9 Dec 2025 17:09:15 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765325351; bh=uL/4p+fTOhYJgUJ6mIimdpQIyyq7fUn3ZzSjyzBThng=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hYo0etS8UuP6ewJyCxoXDGm/9HqrB6BHVwwNRWpKko4qmS1tk8rA9MY9xIlMRdH9a KfEdzGrucAZTOfm1PpqOphcyd7vASYQpEF9Ou9e3pMdf0zleBwhXubqyS52ngaeyKV OkERGf33VCfRrjTPtdIDFKdDQP9R8PvZtU2r+b8ypFmClye3mfGCG2gp1V8DvGQ5nA lw0UnnISfEXeWPCvIK7fe93nf5djmbdOI1p3vtQnwNSgzVEjL9+gjqjz/RGWKFyOd5 2gI8Z/UWzqpLELN8y0lsA56/8DJEpbIiIYUFIXDiP0HQuqu5YU0FFK/8yUVqppfGKS SE20yREHGYDng== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 43EBC6884F; Tue, 9 Dec 2025 17:09:11 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 9 Dec 2025 17:07:07 -0700 Message-ID: <20251210000737.180797-17-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251210000737.180797-1-sjg@u-boot.org> References: <20251210000737.180797-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: O5EUJN7ROJGIHMWRNVXEEEPLXW5QIMZB X-Message-ID-Hash: O5EUJN7ROJGIHMWRNVXEEEPLXW5QIMZB X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 16/35] malloc: Add a Kconfig option for debugging malloc() 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 new CONFIG_MALLOC_DEBUG option to control malloc() debugging features. This replaces the direct UNIT_TEST check and allows enabling malloc debugging independently of whether UNIT_TEST is enabled. The option defaults to y when UNIT_TEST is enabled, preserving existing behaviour. Disable for RISC-V since it seems to have a size limitation. Co-developed-by: Claude Signed-off-by: Simon Glass --- Kconfig | 8 ++++++++ common/dlmalloc.c | 2 +- include/malloc.h | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Kconfig b/Kconfig index 378ecfb1867..86276c89f38 100644 --- a/Kconfig +++ b/Kconfig @@ -337,6 +337,14 @@ config SYS_MALLOC_LEN This defines memory to be allocated for Dynamic allocation TODO: Use for other architectures +config MALLOC_DEBUG + bool "Enable malloc debugging" + default y if UNIT_TEST && !CPU_RISCV + help + Enable debugging features in the malloc implementation. This + enables additional assertions and the malloc_get_info() function + to retrieve memory-allocation statistics. + config SPL_SYS_MALLOC_F bool "Enable malloc() pool in SPL" depends on SPL_FRAMEWORK && SYS_MALLOC_F && SPL diff --git a/common/dlmalloc.c b/common/dlmalloc.c index 004dafe4b3b..b5dc2b13dc6 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -568,7 +568,7 @@ MAX_RELEASE_CHECK_RATE default: 4095 unless not HAVE_MMAP #ifdef __UBOOT__ -#if CONFIG_IS_ENABLED(UNIT_TEST) +#if CONFIG_IS_ENABLED(MALLOC_DEBUG) #define DEBUG 1 #endif diff --git a/include/malloc.h b/include/malloc.h index fd8a8ddcfaf..7e276d444ab 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -753,9 +753,9 @@ int initf_malloc(void); * malloc_get_info() - Get memory allocation statistics * * @info: Place to put the statistics - * Return: 0 on success, -ENOSYS if not available (DEBUG not defined) + * Return: 0 on success, -ENOSYS if not available (MALLOC_DEBUG not enabled) */ -#ifdef DEBUG +#if CONFIG_IS_ENABLED(MALLOC_DEBUG) int malloc_get_info(struct malloc_info *info); #else static inline int malloc_get_info(struct malloc_info *info)