]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
selinux: simplify range_write()
authorOndrej Mosnacek <omosnace@redhat.com>
Tue, 28 Apr 2020 12:55:11 +0000 (14:55 +0200)
committerPaul Moore <paul@paul-moore.com>
Fri, 1 May 2020 20:08:04 +0000 (16:08 -0400)
No need to traverse the hashtab to count its elements, hashtab already
tracks it for us.

Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/ss/policydb.c

index a42369dd96a96b7a0ac2830eccaac6627a803839..8a287a7afd9f7c63daaecede55c7f146a84c0646 100644 (file)
@@ -3405,14 +3405,6 @@ static int genfs_write(struct policydb *p, void *fp)
        return 0;
 }
 
-static int hashtab_cnt(void *key, void *data, void *ptr)
-{
-       int *cnt = ptr;
-       *cnt = *cnt + 1;
-
-       return 0;
-}
-
 static int range_write_helper(void *key, void *data, void *ptr)
 {
        __le32 buf[2];
@@ -3444,19 +3436,13 @@ static int range_write_helper(void *key, void *data, void *ptr)
 static int range_write(struct policydb *p, void *fp)
 {
        __le32 buf[1];
-       int rc, nel;
+       int rc;
        struct policy_data pd;
 
        pd.p = p;
        pd.fp = fp;
 
-       /* count the number of entries in the hashtab */
-       nel = 0;
-       rc = hashtab_map(p->range_tr, hashtab_cnt, &nel);
-       if (rc)
-               return rc;
-
-       buf[0] = cpu_to_le32(nel);
+       buf[0] = cpu_to_le32(p->range_tr->nel);
        rc = put_entry(buf, sizeof(u32), 1, fp);
        if (rc)
                return rc;