From patchwork Sun Mar 22 23:57:00 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2034 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=1774223863; bh=3u1kqUmOAjmQFwx5lVuJyKi3OKdNor3Tin8rtHeFMzg=; 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=pp/JIQDw+8UGOLY82eCXVnTcr+yN6qrRSNTNJxdUSoc6Z99Z8sfiJYl1R7woUATdi aH0kBYiNc8jBl8oXBLVhunLtN0vKNYYLW4rwKDt17LXyyAmHLMzV4w5KsuXsjhj3UP vkGSjbEAkEc+b7uSa+9Q+srlEeTKb7gXsEWDqGSnYG39nrDdDprpjSTukuQaIV0LT3 qz5T0eUQQbe4c0teFLLeIHJJFuGl3OJtelIE342hLEiPFhfE9MgmbdwgpnwuSRti5w Rj8GXHlhbFS4MX5GS9EvYjKE3HEc4ncoQn6dH5RT8OiAfT+dAkV2rou/TKguNZYStX ki5yAJDbpy6xg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 916956A1DF for ; Sun, 22 Mar 2026 17:57:43 -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 8RI2RKZMeBQs for ; Sun, 22 Mar 2026 17:57:43 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1774223863; bh=3u1kqUmOAjmQFwx5lVuJyKi3OKdNor3Tin8rtHeFMzg=; 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=pp/JIQDw+8UGOLY82eCXVnTcr+yN6qrRSNTNJxdUSoc6Z99Z8sfiJYl1R7woUATdi aH0kBYiNc8jBl8oXBLVhunLtN0vKNYYLW4rwKDt17LXyyAmHLMzV4w5KsuXsjhj3UP vkGSjbEAkEc+b7uSa+9Q+srlEeTKb7gXsEWDqGSnYG39nrDdDprpjSTukuQaIV0LT3 qz5T0eUQQbe4c0teFLLeIHJJFuGl3OJtelIE342hLEiPFhfE9MgmbdwgpnwuSRti5w Rj8GXHlhbFS4MX5GS9EvYjKE3HEc4ncoQn6dH5RT8OiAfT+dAkV2rou/TKguNZYStX ki5yAJDbpy6xg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 77F0C6A1DE for ; Sun, 22 Mar 2026 17:57:43 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1774223857; bh=rossbgSFpLTNJH6VWbv8Spl9LtOEQJaXojcxyNS0/Fo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=reX3+KE+uPXGQjDOWbReH9A3FuNcxbjyGsOsM0n2BIoJJvxwpgKA95w32mVBwiH6d +gz60o5+O4Y1fybNnbAiTPWzOjFK6CXdr5MBNHolI4s5PIaV48hMHF54BV19WCi/pd KkFbKmi5dALHUCf+W9fuU6xDl4p5f41Gs4HeQYUi/X5c7bGXvPsF9osR3Gutc6qxQ5 gbM1ckdNPVFgcXGCvWP6ivve/HOLESdMJgt9+C+G6+ujzcpJuQfgqSpxQBvaQWJGeV 0+8ES4p92YxU/zvVSJ384CMTt4NfaL9XQs65FWa2EA0dmzzBthUjD2hnJtxSjQIY3w 5wvrhsAbwsMFw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id EFA2E6A1DC; Sun, 22 Mar 2026 17:57:37 -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 sAZaZdf7QekC; Sun, 22 Mar 2026 17:57:37 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1774223857; bh=ezxSgjoc1xZObr1HEx/aNyjzmIWmqtfSaz2xqwQOatE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hcy5EA62KtsGWZOuMk8tFh6WdXvynfXUlxKMPsLnvdATX8E/cCKXyAbPRK3Qah91k cb8JZY8TMjpuIz+TOVpc421FEkxhaxAQ+1YnodMls4sbEt/w7g7Q/+zE/+UelEWU8X KCwercAZ03LeS3CGVNRfFTgx6JtxDo5JWTGmhKqe9PiqanI1QkcLBFGECjSth1+rI+ 1NAMDfCquj6AiVloe9xZLrOhXISQE4uqrnZUpScTmd8hQOLzK/FN+EKBwYt/d697AQ JMEH1D90O+7LFNw70gwkZDHimnwodL6SFARfMbSy9jM2DvIBAj07jNMp+3xS1gtq3p twTDhQJARQpcg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id DB0086A1D9; Sun, 22 Mar 2026 17:57:36 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Sun, 22 Mar 2026 17:57:00 -0600 Message-ID: <20260322235719.1729267-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260322235719.1729267-1-sjg@u-boot.org> References: <20260322235719.1729267-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: PW3VH2AOKYR3ULO66S6GT6P234QC3MZ2 X-Message-ID-Hash: PW3VH2AOKYR3ULO66S6GT6P234QC3MZ2 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/14] alist: Zero new entries in alist_add_placeholder() 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 It is convenient for alist_add_placeholder() to zero the entry before returning it. This saves callers from needing to do it themselves. Update an alist test to verify the new entry is zeroed. Signed-off-by: Simon Glass --- include/alist.h | 7 +++---- lib/alist.c | 8 +++++++- test/lib/alist.c | 10 ++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) -- 2.43.0 diff --git a/include/alist.h b/include/alist.h index 69d7cdb722f..7b368a7e09a 100644 --- a/include/alist.h +++ b/include/alist.h @@ -174,12 +174,11 @@ void *alist_ensure_ptr(struct alist *lst, uint index); ((_struct *)alist_ensure_ptr(_lst, _index)) /** - * alist_add_placeholder() - Add a new item to the end of the list + * alist_add_placeholder() - Add a new zeroed item to the end of the list * * @lst: alist to add to - * Return: Pointer to the newly added position, or NULL if out of memory. Note - * that this is not inited so the caller must copy the requested struct to the - * returned pointer + * Return: Pointer to the newly added position (zeroed), or NULL if out of + * memory */ void *alist_add_placeholder(struct alist *lst); diff --git a/lib/alist.c b/lib/alist.c index 0ae07f0f5c0..b9ddd4103c4 100644 --- a/lib/alist.c +++ b/lib/alist.c @@ -165,7 +165,13 @@ void *alist_ensure_ptr(struct alist *lst, uint index) void *alist_add_placeholder(struct alist *lst) { - return alist_ensure_ptr(lst, lst->count); + void *ptr; + + ptr = alist_ensure_ptr(lst, lst->count); + if (ptr) + memset(ptr, '\0', lst->obj_size); + + return ptr; } void *alist_add_ptr(struct alist *lst, void *obj) diff --git a/test/lib/alist.c b/test/lib/alist.c index 108eaed8d92..8e958ed9398 100644 --- a/test/lib/alist.c +++ b/test/lib/alist.c @@ -219,8 +219,18 @@ static int lib_test_alist_add(struct unit_test_state *uts) ut_asserteq(123, ptr->val); ut_asserteq(456, ptr->other_val); + /* Add a non-zero entry then remove it, so the memory is dirty */ ptr2 = alist_add_placeholder(&lst); ut_assertnonnull(ptr2); + ptr2->val = 999; + ptr2->other_val = 888; + lst.count--; + + /* Now add again — the slot should be zeroed despite dirty memory */ + ptr2 = alist_add_placeholder(&lst); + ut_assertnonnull(ptr2); + ut_asserteq(0, ptr2->val); + ut_asserteq(0, ptr2->other_val); ptr2->val = 321; ptr2->other_val = 654;