Commit 5c7001b8 authored by Himangi Saraogi's avatar Himangi Saraogi Committed by Paul Moore

SELinux: use ARRAY_SIZE

ARRAY_SIZE is more concise to use when the size of an array is divided
by the size of its type or the size of its first element.

The Coccinelle semantic patch that makes this change is as follows:

// <smpl>
@@
type T;
T[] E;
@@

- (sizeof(E)/sizeof(E[...]))
+ ARRAY_SIZE(E)
// </smpl>
Signed-off-by: default avatarHimangi Saraogi <himangi774@gmail.com>
Signed-off-by: default avatarPaul Moore <pmoore@redhat.com>
parent aa65506f
...@@ -2608,7 +2608,7 @@ static int mls_write_range_helper(struct mls_range *r, void *fp) ...@@ -2608,7 +2608,7 @@ static int mls_write_range_helper(struct mls_range *r, void *fp)
if (!eq) if (!eq)
buf[2] = cpu_to_le32(r->level[1].sens); buf[2] = cpu_to_le32(r->level[1].sens);
BUG_ON(items > (sizeof(buf)/sizeof(buf[0]))); BUG_ON(items > ARRAY_SIZE(buf));
rc = put_entry(buf, sizeof(u32), items, fp); rc = put_entry(buf, sizeof(u32), items, fp);
if (rc) if (rc)
...@@ -2990,7 +2990,7 @@ static int role_write(void *vkey, void *datum, void *ptr) ...@@ -2990,7 +2990,7 @@ static int role_write(void *vkey, void *datum, void *ptr)
if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) if (p->policyvers >= POLICYDB_VERSION_BOUNDARY)
buf[items++] = cpu_to_le32(role->bounds); buf[items++] = cpu_to_le32(role->bounds);
BUG_ON(items > (sizeof(buf)/sizeof(buf[0]))); BUG_ON(items > ARRAY_SIZE(buf));
rc = put_entry(buf, sizeof(u32), items, fp); rc = put_entry(buf, sizeof(u32), items, fp);
if (rc) if (rc)
...@@ -3040,7 +3040,7 @@ static int type_write(void *vkey, void *datum, void *ptr) ...@@ -3040,7 +3040,7 @@ static int type_write(void *vkey, void *datum, void *ptr)
} else { } else {
buf[items++] = cpu_to_le32(typdatum->primary); buf[items++] = cpu_to_le32(typdatum->primary);
} }
BUG_ON(items > (sizeof(buf) / sizeof(buf[0]))); BUG_ON(items > ARRAY_SIZE(buf));
rc = put_entry(buf, sizeof(u32), items, fp); rc = put_entry(buf, sizeof(u32), items, fp);
if (rc) if (rc)
return rc; return rc;
...@@ -3069,7 +3069,7 @@ static int user_write(void *vkey, void *datum, void *ptr) ...@@ -3069,7 +3069,7 @@ static int user_write(void *vkey, void *datum, void *ptr)
buf[items++] = cpu_to_le32(usrdatum->value); buf[items++] = cpu_to_le32(usrdatum->value);
if (p->policyvers >= POLICYDB_VERSION_BOUNDARY) if (p->policyvers >= POLICYDB_VERSION_BOUNDARY)
buf[items++] = cpu_to_le32(usrdatum->bounds); buf[items++] = cpu_to_le32(usrdatum->bounds);
BUG_ON(items > (sizeof(buf) / sizeof(buf[0]))); BUG_ON(items > ARRAY_SIZE(buf));
rc = put_entry(buf, sizeof(u32), items, fp); rc = put_entry(buf, sizeof(u32), items, fp);
if (rc) if (rc)
return rc; return rc;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment