Skip to content

Commit 3348bd3

Browse files
WOnder93pcmoore
authored andcommitted
selinux: simplify range_write()
No need to traverse the hashtab to count its elements, hashtab already tracks it for us. Signed-off-by: Ondrej Mosnacek <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 4c09f8b commit 3348bd3

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

security/selinux/ss/policydb.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3405,14 +3405,6 @@ static int genfs_write(struct policydb *p, void *fp)
34053405
return 0;
34063406
}
34073407

3408-
static int hashtab_cnt(void *key, void *data, void *ptr)
3409-
{
3410-
int *cnt = ptr;
3411-
*cnt = *cnt + 1;
3412-
3413-
return 0;
3414-
}
3415-
34163408
static int range_write_helper(void *key, void *data, void *ptr)
34173409
{
34183410
__le32 buf[2];
@@ -3444,19 +3436,13 @@ static int range_write_helper(void *key, void *data, void *ptr)
34443436
static int range_write(struct policydb *p, void *fp)
34453437
{
34463438
__le32 buf[1];
3447-
int rc, nel;
3439+
int rc;
34483440
struct policy_data pd;
34493441

34503442
pd.p = p;
34513443
pd.fp = fp;
34523444

3453-
/* count the number of entries in the hashtab */
3454-
nel = 0;
3455-
rc = hashtab_map(p->range_tr, hashtab_cnt, &nel);
3456-
if (rc)
3457-
return rc;
3458-
3459-
buf[0] = cpu_to_le32(nel);
3445+
buf[0] = cpu_to_le32(p->range_tr->nel);
34603446
rc = put_entry(buf, sizeof(u32), 1, fp);
34613447
if (rc)
34623448
return rc;

0 commit comments

Comments
 (0)