summaryrefslogtreecommitdiffstats
path: root/lib/rhashtable.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2017-04-28 02:10:48 -0400
committerDavid S. Miller <davem@davemloft.net>2017-04-28 10:14:09 -0400
commit2d2ab658d2debcb4c0e29c9e6f18e5683f3077bf (patch)
tree163eada4e9bf806b7057e5b5843820be1b6d0ff5 /lib/rhashtable.c
parente221c1f0fe2590042b4f8c3a8ccccd8e7bed2c31 (diff)
rhashtable: Do not lower max_elems when max_size is zero
The commit 6d684e54690c ("rhashtable: Cap total number of entries to 2^31") breaks rhashtable users that do not set max_size. This is because when max_size is zero max_elems is also incorrectly set to zero instead of 2^31. This patch fixes it by only lowering max_elems when max_size is not zero. Fixes: 6d684e54690c ("rhashtable: Cap total number of entries to 2^31") Reported-by: Florian Fainelli <f.fainelli@gmail.com> Reported-by: kernel test robot <fengguang.wu@intel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'lib/rhashtable.c')
-rw-r--r--lib/rhashtable.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 751630bbe409..3895486ef551 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -958,13 +958,14 @@ int rhashtable_init(struct rhashtable *ht,
958 if (params->min_size) 958 if (params->min_size)
959 ht->p.min_size = roundup_pow_of_two(params->min_size); 959 ht->p.min_size = roundup_pow_of_two(params->min_size);
960 960
961 if (params->max_size)
962 ht->p.max_size = rounddown_pow_of_two(params->max_size);
963
964 /* Cap total entries at 2^31 to avoid nelems overflow. */ 961 /* Cap total entries at 2^31 to avoid nelems overflow. */
965 ht->max_elems = 1u << 31; 962 ht->max_elems = 1u << 31;
966 if (ht->p.max_size < ht->max_elems / 2) 963
967 ht->max_elems = ht->p.max_size * 2; 964 if (params->max_size) {
965 ht->p.max_size = rounddown_pow_of_two(params->max_size);
966 if (ht->p.max_size < ht->max_elems / 2)
967 ht->max_elems = ht->p.max_size * 2;
968 }
968 969
969 ht->p.min_size = max(ht->p.min_size, HASH_MIN_SIZE); 970 ht->p.min_size = max(ht->p.min_size, HASH_MIN_SIZE);
970 971