Skip to content

Commit be30b16

Browse files
committed
SELinux: calculate and print hashtab stats with a generic function
We have custom debug functions like rangetr_hash_eval and symtab_hash_eval which do the same thing. Just create a generic function that takes the name of the hash table as an argument instead of having custom functions. Signed-off-by: Eric Paris <[email protected]> Reviewed-by: James Morris <[email protected]>
1 parent 03a4c01 commit be30b16

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

security/selinux/ss/policydb.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -423,32 +423,26 @@ static int (*index_f[SYM_NUM]) (void *key, void *datum, void *datap) =
423423
};
424424

425425
#ifdef DEBUG_HASHES
426-
static void symtab_hash_eval(struct symtab *s)
426+
static void hash_eval(struct hashtab *h, const char *hash_name)
427427
{
428-
int i;
429-
430-
for (i = 0; i < SYM_NUM; i++) {
431-
struct hashtab *h = s[i].table;
432-
struct hashtab_info info;
428+
struct hashtab_info info;
433429

434-
hashtab_stat(h, &info);
435-
printk(KERN_DEBUG "SELinux: %s: %d entries and %d/%d buckets used, "
436-
"longest chain length %d\n", symtab_name[i], h->nel,
437-
info.slots_used, h->size, info.max_chain_len);
438-
}
430+
hashtab_stat(h, &info);
431+
printk(KERN_DEBUG "SELinux: %s: %d entries and %d/%d buckets used, "
432+
"longest chain length %d\n", hash_name, h->nel,
433+
info.slots_used, h->size, info.max_chain_len);
439434
}
440435

441-
static void rangetr_hash_eval(struct hashtab *h)
436+
static void symtab_hash_eval(struct symtab *s)
442437
{
443-
struct hashtab_info info;
438+
int i;
444439

445-
hashtab_stat(h, &info);
446-
printk(KERN_DEBUG "SELinux: rangetr: %d entries and %d/%d buckets used, "
447-
"longest chain length %d\n", h->nel,
448-
info.slots_used, h->size, info.max_chain_len);
440+
for (i = 0; i < SYM_NUM; i++)
441+
hash_eval(s[i].table, symtab_name[i]);
449442
}
443+
450444
#else
451-
static inline void rangetr_hash_eval(struct hashtab *h)
445+
static inline void hash_eval(struct hashtab *h, char *hash_name)
452446
{
453447
}
454448
#endif
@@ -1802,7 +1796,7 @@ static int range_read(struct policydb *p, void *fp)
18021796
rt = NULL;
18031797
r = NULL;
18041798
}
1805-
rangetr_hash_eval(p->range_tr);
1799+
hash_eval(p->range_tr, "rangetr");
18061800
rc = 0;
18071801
out:
18081802
kfree(rt);

0 commit comments

Comments
 (0)