Skip to content

Commit 7969ba5

Browse files
cgzonespcmoore
authored andcommitted
selinux: simplify avtab slot calculation
Instead of dividing by 8 and then performing log2 by hand, use a more readable calculation. The behavior of rounddown_pow_of_two() for an input of 0 is undefined, so handle that case and small values manually to achieve the same results. Signed-off-by: Christian Göttsche <cgzones@googlemail.com> Reviewed-by: Stephen Smalley <stephen.smalley.work@gmail.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 6f594f5 commit 7969ba5

1 file changed

Lines changed: 1 addition & 7 deletions

File tree

security/selinux/ss/avtab.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,7 @@ int avtab_alloc(struct avtab *h, u32 nrules)
298298
u32 nslot = 0;
299299

300300
if (nrules != 0) {
301-
u32 shift = 1;
302-
u32 work = nrules >> 3;
303-
while (work) {
304-
work >>= 1;
305-
shift++;
306-
}
307-
nslot = 1 << shift;
301+
nslot = nrules > 3 ? rounddown_pow_of_two(nrules / 2) : 2;
308302
if (nslot > MAX_AVTAB_HASH_BUCKETS)
309303
nslot = MAX_AVTAB_HASH_BUCKETS;
310304

0 commit comments

Comments
 (0)