Commit 7969ba57 authored by Christian Göttsche's avatar Christian Göttsche Committed by Paul Moore
Browse files

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: default avatarChristian Göttsche <cgzones@googlemail.com>
Reviewed-by: default avatarStephen Smalley <stephen.smalley.work@gmail.com>
Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
parent 6f594f5a
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
@@ -298,13 +298,7 @@ int avtab_alloc(struct avtab *h, u32 nrules)
	u32 nslot = 0;

	if (nrules != 0) {
		u32 shift = 1;
		u32 work = nrules >> 3;
		while (work) {
			work >>= 1;
			shift++;
		}
		nslot = 1 << shift;
		nslot = nrules > 3 ? rounddown_pow_of_two(nrules / 2) : 2;
		if (nslot > MAX_AVTAB_HASH_BUCKETS)
			nslot = MAX_AVTAB_HASH_BUCKETS;