aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/inet_hashtables.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv4/inet_hashtables.c')
-rw-r--r--net/ipv4/inet_hashtables.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index f8b3701a6c3c..89120196a949 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -610,22 +610,21 @@ EXPORT_SYMBOL_GPL(inet_hashinfo_init);
610 610
611int inet_ehash_locks_alloc(struct inet_hashinfo *hashinfo) 611int inet_ehash_locks_alloc(struct inet_hashinfo *hashinfo)
612{ 612{
613 unsigned int locksz = sizeof(spinlock_t);
613 unsigned int i, nblocks = 1; 614 unsigned int i, nblocks = 1;
614 615
615 if (sizeof(spinlock_t) != 0) { 616 if (locksz != 0) {
616 /* allocate 2 cache lines or at least one spinlock per cpu */ 617 /* allocate 2 cache lines or at least one spinlock per cpu */
617 nblocks = max_t(unsigned int, 618 nblocks = max(2U * L1_CACHE_BYTES / locksz, 1U);
618 2 * L1_CACHE_BYTES / sizeof(spinlock_t),
619 1);
620 nblocks = roundup_pow_of_two(nblocks * num_possible_cpus()); 619 nblocks = roundup_pow_of_two(nblocks * num_possible_cpus());
621 620
622 /* no more locks than number of hash buckets */ 621 /* no more locks than number of hash buckets */
623 nblocks = min(nblocks, hashinfo->ehash_mask + 1); 622 nblocks = min(nblocks, hashinfo->ehash_mask + 1);
624 623
625 hashinfo->ehash_locks = kmalloc_array(nblocks, sizeof(spinlock_t), 624 hashinfo->ehash_locks = kmalloc_array(nblocks, locksz,
626 GFP_KERNEL | __GFP_NOWARN); 625 GFP_KERNEL | __GFP_NOWARN);
627 if (!hashinfo->ehash_locks) 626 if (!hashinfo->ehash_locks)
628 hashinfo->ehash_locks = vmalloc(nblocks * sizeof(spinlock_t)); 627 hashinfo->ehash_locks = vmalloc(nblocks * locksz);
629 628
630 if (!hashinfo->ehash_locks) 629 if (!hashinfo->ehash_locks)
631 return -ENOMEM; 630 return -ENOMEM;