From patchwork Mon Dec 1 17:04:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 792 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=1764608934; bh=O9bhpdC+0rP1LcX/r9O07nY3DWyQxD1kBwKIlk/IFrw=; 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=v0ajsZ0/AY1JyUzezR/mSvSIZGz+v3SPvsJvz8fuolyPPrNwD3eAgN7E4uAIgIjav Ch6Q060PgiVqdL+cKC0TstMuJGXtFYcl+u2jnA+mdoQXjXW7TF09XZghygcsNeh0Mw tF4jKoCmmccgk/o5opCjhaExrzo8o3F0hWjDgpxtpT6O1COUo5EZtbBHzq5e4VGX7c wWrRySgItmWml9pB9tvBhY4omC1ca7G6vIjIHITqyOh5hilB4PL3rVp8c7CTv5KTVV w8z+dQ3T8rAHqlc1jCA9BQ1TCCfjXilp7sbbvpnV1Z58Yo2LgBZEs9O6E7TEohfew6 MQ/N1WjUvEUKA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 23464688C5 for ; Mon, 1 Dec 2025 10:08:54 -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 sqEA8AmFCnS4 for ; Mon, 1 Dec 2025 10:08:54 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608934; bh=O9bhpdC+0rP1LcX/r9O07nY3DWyQxD1kBwKIlk/IFrw=; 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=v0ajsZ0/AY1JyUzezR/mSvSIZGz+v3SPvsJvz8fuolyPPrNwD3eAgN7E4uAIgIjav Ch6Q060PgiVqdL+cKC0TstMuJGXtFYcl+u2jnA+mdoQXjXW7TF09XZghygcsNeh0Mw tF4jKoCmmccgk/o5opCjhaExrzo8o3F0hWjDgpxtpT6O1COUo5EZtbBHzq5e4VGX7c wWrRySgItmWml9pB9tvBhY4omC1ca7G6vIjIHITqyOh5hilB4PL3rVp8c7CTv5KTVV w8z+dQ3T8rAHqlc1jCA9BQ1TCCfjXilp7sbbvpnV1Z58Yo2LgBZEs9O6E7TEohfew6 MQ/N1WjUvEUKA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 102F16881A for ; Mon, 1 Dec 2025 10:08:54 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608931; bh=FwTIHEFcel06/stTUN6mcpEOpbWAPgabWJQH7wF1ExI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AHDm22UwSMCxefnjDpJXKhniqqaUyVjUOEdZEKWWbd9EwftTM8cHL685Z0NNXxGs8 aoYymaKcRVrPFA9UvfJ/6w5DCaBvVJs+P9ZLWPlqA+hDw16bPQlrEIryn2OwrGhzjM v9DHgG+6RaFg1BW9XCvgL8y7K7OBE4QH99+c6ekxGbJdndWHzKSnjA6bIh73hRauZm 1a6oHdT30gxFLQCbFrOCPA7GtxGph7sFarRRtC7g96j4GRFYdRUS2QgVpC0IkTL5cK xvhVh0qMffimJ9XK1sBUjamyCpZdeUqwHBnRJSIlpNTuU5FSN8j2DKp/PU6UEtPI5S ystUXly0XLa5Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B73F4688A7; Mon, 1 Dec 2025 10:08:51 -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 VB7qpjBxWstI; Mon, 1 Dec 2025 10:08:51 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608927; bh=U/u+kuqKFdn5IcQy9guvW75SiuDiZJDCJ1E2qVWi6/k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kMDZI60OMx7mPmR1O5virybsjh4j2vLlq8nbZUcvqbglSO7UlBNtbPRsJcEhMvJWw 6UWqPjG8J2aoe4+C8WaFeoEeNLgW8NcWdFzKhCgHok3BsopP01rPWNwSevZu8a6tuD 0blBk2imYfJ+ZbORJutwly+wMau3/6dsGcdGpzs8ZzcFqCWuDn6tFJM3zv7GTFZOOs kTbIHj+9Ll80yzRGQRDyhOlzsR3zZmYR1L1xMND9T7aTvkvl0z4bJa9yqOXd+/O49m ZIuTTgFLMyZrRVt/wSy2o8KW2nAS3fL0u3789MOGVdNRQ+FdQCBuOr73ja+GRh2B88 U5h83gym1kNrA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id E75375E439; Mon, 1 Dec 2025 10:08:46 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Mon, 1 Dec 2025 10:04:56 -0700 Message-ID: <20251201170529.3237986-18-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251201170529.3237986-1-sjg@u-boot.org> References: <20251201170529.3237986-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: P6MBNPFVC5SWXOXYI3F7CWDCW7IB4NME X-Message-ID-Hash: P6MBNPFVC5SWXOXYI3F7CWDCW7IB4NME 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 , Simon Goldschmidt , Tom Rini , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 17/37] dlmalloc: calloc: fix zeroing early allocations 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 full malloc is enabled and SYS_MALLOC_F is also enabled, the simple pre-reloc heap is used before relocation. The calloc_must_clear macro relies on chunk metadata which does not exist for simple malloc allocations. Use memset directly to zero out memory from simple malloc. Changes from original commit: - Port to dlcalloc() in dlmalloc 2.8.6 - Update memset() second arg to be a char Signed-off-by: Simon Goldschmidt Reviewed-by: Tom Rini Co-developed-by: Claude Signed-off-by: Simon Glass (cherry picked from bb71a2d9dcd9c53aa4d4b8e4d26c24d9b59b74c3) --- common/dlmalloc.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index d53cbf2f2e1..a07166206dc 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -4877,6 +4877,15 @@ void* dlcalloc(size_t n_elements, size_t elem_size) { req = MAX_SIZE_T; /* force downstream failure on overflow */ } mem = dlmalloc(req); +#ifdef __UBOOT__ +#if CONFIG_IS_ENABLED(SYS_MALLOC_F) + /* For pre-reloc simple malloc, just zero the memory directly */ + if (mem != 0 && !(gd->flags & GD_FLG_FULL_MALLOC_INIT)) { + memset(mem, '\0', req); + return mem; + } +#endif +#endif if (mem != 0 && calloc_must_clear(mem2chunk(mem))) memset(mem, 0, req); return mem;