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....@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
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to