diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2023-08-18 17:12:15 +0200 |
---|---|---|
committer | Paul Moore <paul@paul-moore.com> | 2023-09-13 13:46:57 -0400 |
commit | 7969ba577636a83553baf95882eb310b39e1c742 (patch) | |
tree | 44e772d2e06954959516abf8713218ec7c61d9b6 | |
parent | 6f594f5a3dc4917be1556e524673420197ca471d (diff) | |
download | linux-stable-7969ba577636a83553baf95882eb310b39e1c742.tar.gz linux-stable-7969ba577636a83553baf95882eb310b39e1c742.tar.bz2 linux-stable-7969ba577636a83553baf95882eb310b39e1c742.zip |
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>
-rw-r--r-- | security/selinux/ss/avtab.c | 8 |
1 files changed, 1 insertions, 7 deletions
diff --git a/security/selinux/ss/avtab.c b/security/selinux/ss/avtab.c index 955cfe495606..1d1ffe085b35 100644 --- a/security/selinux/ss/avtab.c +++ b/security/selinux/ss/avtab.c @@ -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; |