Skip to content

Commit 34ae685

Browse files
fsorensontrondmypd
authored andcommitted
sunrpc: Fix bit count when setting hashtable size to power-of-two
Author: Frank Sorenson <sorenson@redhat.com> 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 <sorenson@redhat.com> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
1 parent b224f7c commit 34ae685

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

net/sunrpc/auth.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ static int param_set_hashtbl_sz(const char *val, const struct kernel_param *kp)
5151
ret = kstrtoul(val, 0, &num);
5252
if (ret == -EINVAL)
5353
goto out_inval;
54-
nbits = fls(num);
55-
if (num > (1U << nbits))
56-
nbits++;
54+
nbits = fls(num - 1);
5755
if (nbits > MAX_HASHTABLE_BITS || nbits < 2)
5856
goto out_inval;
5957
*(unsigned int *)kp->arg = nbits;

0 commit comments

Comments
 (0)