netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: William Hua <william.hua@canonical.com>
To: netdev@vger.kernel.org, Thomas Graf <tgraf@suug.ch>
Cc: William Hua <william.hua@canonical.com>
Subject: [PATCH] rhashtable: Always allocate at least one bucket lock
Date: Tue, 15 Dec 2015 17:45:59 -0500	[thread overview]
Message-ID: <56709827.1010407@canonical.com> (raw)

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

             reply	other threads:[~2015-12-15 22:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-15 22:45 William Hua [this message]
2015-12-16  5:53 ` [PATCH] rhashtable: Always allocate at least one bucket lock 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56709827.1010407@canonical.com \
    --to=william.hua@canonical.com \
    --cc=netdev@vger.kernel.org \
    --cc=tgraf@suug.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).