Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 170029d6 authored by Jeevan Shriram's avatar Jeevan Shriram
Browse files

net: ipv4: hashtables: avoid division by zero compilation error



Since sizeof(spinlock_t) is calculated everytime and may be used as
divisor in equation, compiler throws an error division by zero. Use
a variable to store the value of sizeof(spinlock_t) and in equations.

Change-Id: I60908c71ca1fe373211f7955e75a1a5889dcf8e2
Signed-off-by: default avatarJeevan Shriram <jshriram@codeaurora.org>
parent 4c0cc16e
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -599,22 +599,22 @@ EXPORT_SYMBOL_GPL(inet_hashinfo_init);

int inet_ehash_locks_alloc(struct inet_hashinfo *hashinfo)
{
	unsigned int i, nblocks = 1;
	unsigned int i, nblocks = 1, size;

	if (sizeof(spinlock_t) != 0) {
	size = sizeof(spinlock_t);
	if (size != 0) {
		/* allocate 2 cache lines or at least one spinlock per cpu */
		nblocks = max_t(unsigned int,
				2 * L1_CACHE_BYTES / sizeof(spinlock_t),
				1);
				2 * L1_CACHE_BYTES / size, 1);
		nblocks = roundup_pow_of_two(nblocks * num_possible_cpus());

		/* no more locks than number of hash buckets */
		nblocks = min(nblocks, hashinfo->ehash_mask + 1);

		hashinfo->ehash_locks =	kmalloc_array(nblocks, sizeof(spinlock_t),
		hashinfo->ehash_locks =	kmalloc_array(nblocks, size,
						      GFP_KERNEL | __GFP_NOWARN);
		if (!hashinfo->ehash_locks)
			hashinfo->ehash_locks = vmalloc(nblocks * sizeof(spinlock_t));
			hashinfo->ehash_locks = vmalloc(nblocks * size);

		if (!hashinfo->ehash_locks)
			return -ENOMEM;