Skip to contentSkip to conversation

lru_cache: Initialize hlist_head in lc_create

PATCH In review I-HSIN CHENG 2 participants 2 messages Mar 11, 2024 – Apr 16, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lru_cache: Initialize hlist_head in lc_create

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.

---
 lib/lru_cache.c | 3 +++
 1 file changed, 3 insertions(+)
lib/lru_cache.c +3 -0
index b3d918761..f2197aae1 100644
@@ -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 * sizeof(struct hlist_head)));
+
 	INIT_LIST_HEAD(&lc->in_use);
 	INIT_LIST_HEAD(&lc->lru);
 	INIT_LIST_HEAD(&lc->free);
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 3 lines · I-HSIN CHENG

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.

Completely pointless. It is kcalloc'd. Why explicitly zero-out something that was already explicitly zeroed out to begin with.

Lars