netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rhashtable: Always allocate at least one bucket lock
@ 2015-12-15 22:45 William Hua
  2015-12-16  5:53 ` Herbert Xu
  0 siblings, 1 reply; 5+ messages in thread
From: William Hua @ 2015-12-15 22:45 UTC (permalink / raw)
  To: netdev, Thomas Graf; +Cc: William Hua

No bucket locks are allocated when an rhashtable is initialized with
fewer than two elements. In this special case, we should allocate at
least one to prevent a segfault.

Signed-off-by: William Hua <william.hua@canonical.com>
---
 lib/rhashtable.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index a54ff89..1b1b5b2 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -76,6 +76,9 @@ static int alloc_bucket_locks(struct rhashtable *ht, struct bucket_table *tbl,
 	/* Never allocate more than 0.5 locks per bucket */
 	size = min_t(unsigned int, size, tbl->size >> 1);
 
+	/* Always allocate at least one lock */
+	size = max_t(unsigned int, size, 1);
+
 	if (sizeof(spinlock_t) != 0) {
 #ifdef CONFIG_NUMA
 		if (size * sizeof(spinlock_t) > PAGE_SIZE &&
-- 
2.6.4

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

end of thread, other threads:[~2015-12-16 15:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-15 22:45 [PATCH] rhashtable: Always allocate at least one bucket lock William Hua
2015-12-16  5:53 ` Herbert Xu
2015-12-16  7:33   ` William Hua
2015-12-16 10:13     ` rhashtable: Enforce minimum size on initial hash table Herbert Xu
2015-12-16 15:45       ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).