From: Frank Sorenson Date: Mon, 27 Jun 2016 19:17:19 +0000 (-0400) Subject: sunrpc: Fix bit count when setting hashtable size to power-of-two X-Git-Tag: v4.8-rc1~87^2~12 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=34ae685cb3ac965c0c733c866412f3b66ddd64e7;p=karo-tx-linux.git sunrpc: Fix bit count when setting hashtable size to power-of-two Author: Frank Sorenson Date: 2016-06-27 13:55:48 -0500 sunrpc: Fix bit count when setting hashtable size to power-of-two The hashtable size is incorrectly calculated as the next higher power-of-two when being set to a power-of-two. fls() returns the bit number of the most significant set bit, with the least significant bit being numbered '1'. For a power-of-two, fls() will return a bit number which is one higher than the number of bits required, leading to a hashtable which is twice the requested size. In addition, the value of (1 << nbits) will always be at least num, so the test will never be true. Fix the hash table size calculation to correctly set hashtable size, and eliminate the unnecessary check. Signed-off-by: Frank Sorenson Signed-off-by: Trond Myklebust --- diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c index 696eb39fc1cb..a7e42f9a405c 100644 --- a/net/sunrpc/auth.c +++ b/net/sunrpc/auth.c @@ -51,9 +51,7 @@ static int param_set_hashtbl_sz(const char *val, const struct kernel_param *kp) ret = kstrtoul(val, 0, &num); if (ret == -EINVAL) goto out_inval; - nbits = fls(num); - if (num > (1U << nbits)) - nbits++; + nbits = fls(num - 1); if (nbits > MAX_HASHTABLE_BITS || nbits < 2) goto out_inval; *(unsigned int *)kp->arg = nbits;