Distributed Replicated Block Device (DRBD) development
 help / color / mirror / Atom feed
* [PATCH] lru_cache: Initialize hlist_head in lc_create
@ 2024-03-11  3:07 I-HSIN CHENG
  2024-04-16 13:42 ` Lars Ellenberg
  0 siblings, 1 reply; 3+ messages in thread
From: I-HSIN CHENG @ 2024-03-11  3:07 UTC (permalink / raw)
  To: philipp.reisner; +Cc: lars.ellenberg, I-HSIN CHENG, linux-kernel, drbd-dev

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 <richard120310@gmail.com>
---
 lib/lru_cache.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/lru_cache.c b/lib/lru_cache.c
index b3d918761..f2197aae1 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 * sizeof(struct hlist_head)));
+
 	INIT_LIST_HEAD(&lc->in_use);
 	INIT_LIST_HEAD(&lc->lru);
 	INIT_LIST_HEAD(&lc->free);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] lru_cache: Initialize hlist_head in lc_create
@ 2024-03-11  3:44 I-HSIN CHENG
  0 siblings, 0 replies; 3+ messages in thread
From: I-HSIN CHENG @ 2024-03-11  3:44 UTC (permalink / raw)
  To: philipp.reisner; +Cc: lars.ellenberg, I-HSIN CHENG, linux-kernel, drbd-dev

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 <richard120310@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] lru_cache: Initialize hlist_head in lc_create
  2024-03-11  3:07 [PATCH] lru_cache: Initialize hlist_head in lc_create I-HSIN CHENG
@ 2024-04-16 13:42 ` Lars Ellenberg
  0 siblings, 0 replies; 3+ messages in thread
From: Lars Ellenberg @ 2024-04-16 13:42 UTC (permalink / raw)
  To: I-HSIN CHENG; +Cc: philipp.reisner, linux-kernel, drbd-dev

On Mon, Mar 11, 2024 at 11:07:35AM +0800, I-HSIN CHENG wrote:
> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-16 13:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-11  3:07 [PATCH] lru_cache: Initialize hlist_head in lc_create I-HSIN CHENG
2024-04-16 13:42 ` Lars Ellenberg
  -- strict thread matches above, loose matches on Subject: below --
2024-03-11  3:44 I-HSIN CHENG

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox