Commit be30b16d43f4781406de0c08c96501dae4cc5a77

Authored by Eric Paris
1 parent 03a4c0182a

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 <eparis@redhat.com>
Reviewed-by: James Morris <jmorris@namei.org>

Showing 1 changed file with 13 additions and 19 deletions Side-by-side Diff

security/selinux/ss/policydb.c
... ... @@ -423,32 +423,26 @@
423 423 };
424 424  
425 425 #ifdef DEBUG_HASHES
426   -static void symtab_hash_eval(struct symtab *s)
  426 +static void hash_eval(struct hashtab *h, const char *hash_name)
427 427 {
428   - int i;
  428 + struct hashtab_info info;
429 429  
430   - for (i = 0; i < SYM_NUM; i++) {
431   - struct hashtab *h = s[i].table;
432   - struct hashtab_info info;
433   -
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);
439 434 }
440 435  
441   -static void rangetr_hash_eval(struct hashtab *h)
  436 +static void symtab_hash_eval(struct symtab *s)
442 437 {
443   - struct hashtab_info info;
  438 + int i;
444 439  
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]);
449 442 }
  443 +
450 444 #else
451   -static inline void rangetr_hash_eval(struct hashtab *h)
  445 +static inline void hash_eval(struct hashtab *h, char *hash_name)
452 446 {
453 447 }
454 448 #endif
... ... @@ -1802,7 +1796,7 @@
1802 1796 rt = NULL;
1803 1797 r = NULL;
1804 1798 }
1805   - rangetr_hash_eval(p->range_tr);
  1799 + hash_eval(p->range_tr, "rangetr");
1806 1800 rc = 0;
1807 1801 out:
1808 1802 kfree(rt);