Skip to content

Commit

Permalink
selinux: simplify range_write()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Ondrej Mosnacek authored and Paul Moore committed May 1, 2020
1 parent 4c09f8b commit 3348bd3
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions security/selinux/ss/policydb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3348bd3

Please sign in to comment.