netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] rhashtable: Warn if min_size or max_size are not a power of two
@ 2015-03-19 16:34 Thomas Graf
  2015-03-19 19:24 ` David Miller
  0 siblings, 1 reply; 11+ messages in thread
From: Thomas Graf @ 2015-03-19 16:34 UTC (permalink / raw)
  To: davem; +Cc: netdev, herbert

The current code correctly limits table size to the next power of two.
This check is solely to catch programming errors.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
---
 lib/rhashtable.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 5f8fe3e..ad218d6 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -933,6 +933,11 @@ int rhashtable_init(struct rhashtable *ht, struct rhashtable_params *params)
 	if (params->nulls_base && params->nulls_base < (1U << RHT_BASE_SHIFT))
 		return -EINVAL;
 
+	WARN_ON(params->min_size &&
+		roundup_pow_of_two(params->min_size) != params->min_size);
+	WARN_ON(params->max_size &&
+		roundup_pow_of_two(params->max_size) != params->max_size);
+
 	params->min_size = max(params->min_size, HASH_MIN_SIZE);
 
 	if (params->nelem_hint)
-- 
1.9.3

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

end of thread, other threads:[~2015-03-20 10:59 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-19 16:34 [PATCH net-next] rhashtable: Warn if min_size or max_size are not a power of two Thomas Graf
2015-03-19 19:24 ` David Miller
2015-03-19 19:46   ` [PATCH net-next v2] " Thomas Graf
2015-03-19 21:02     ` Herbert Xu
2015-03-19 21:15       ` Thomas Graf
2015-03-19 21:49         ` Herbert Xu
2015-03-19 22:02           ` Herbert Xu
2015-03-19 22:31             ` [PATCH net-next] rhashtable: Round up/down min/max_size to ensure we respect limit Thomas Graf
2015-03-19 22:41               ` Herbert Xu
2015-03-20  1:02               ` David Miller
2015-03-20 10:57           ` [PATCH net-next v2] rhashtable: Warn if min_size or max_size are not a power of two David Laight

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).