From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by mail19.linbit.com (LINBIT Mail Daemon) with ESMTP id 6099E420026 for ; Mon, 11 Mar 2024 04:44:08 +0100 (CET) Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1dd3c6c8dbbso5606315ad.1 for ; Sun, 10 Mar 2024 20:44:07 -0700 (PDT) From: I-HSIN CHENG To: philipp.reisner@linbit.com Subject: [PATCH] lru_cache: Initialize hlist_head in lc_create Date: Mon, 11 Mar 2024 11:44:01 +0800 Message-Id: <20240311034401.234854-1-richard120310@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: lars.ellenberg@linbit.com, I-HSIN CHENG , linux-kernel@vger.kernel.org, drbd-dev@lists.linbit.com List-Id: "*Coordination* of development, patches, contributions -- *Questions* \(even to developers\) go to drbd-user, please." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Use INIT_HLIST_HEAD to perform the initialization for each pointer to struct list_head in the variable "slot" to provide more safety and prevent possible bugs from uninitialized behavior. Signed-off-by: I-HSIN CHENG --- lib/lru_cache.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/lru_cache.c b/lib/lru_cache.c index b3d918761..ae122792e 100644 --- a/lib/lru_cache.c +++ b/lib/lru_cache.c @@ -105,6 +105,9 @@ struct lru_cache *lc_create(const char *name, struct kmem_cache *cache, if (!lc) goto out_fail; + for (int i = 0; i < e_count; i++) + INIT_HLIST_HEAD(slot + i); + INIT_LIST_HEAD(&lc->in_use); INIT_LIST_HEAD(&lc->lru); INIT_LIST_HEAD(&lc->free); -- 2.34.1