* [PATCH] SELinux: use ARRAY_SIZE
@ 2014-06-16 20:11 Himangi Saraogi
2014-06-17 21:40 ` Paul Moore
0 siblings, 1 reply; 2+ messages in thread
From: Himangi Saraogi @ 2014-06-16 20:11 UTC (permalink / raw)
To: Paul Moore, Stephen Smalley, Eric Paris, James Morris, selinux,
linux-security-module, linux-kernel
Cc: julia.lawall
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: Himangi Saraogi <himangi774@gmail.com>
---
security/selinux/ss/policydb.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index 9c5cdc2..56eb65f 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -2608,7 +2608,7 @@ static int mls_write_range_helper(struct mls_range *r, void *fp)
if (!eq)
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);
if (rc)
@@ -2990,7 +2990,7 @@ static int role_write(void *vkey, void *datum, void *ptr)
if (p->policyvers >= POLICYDB_VERSION_BOUNDARY)
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);
if (rc)
@@ -3040,7 +3040,7 @@ static int type_write(void *vkey, void *datum, void *ptr)
} else {
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);
if (rc)
return rc;
@@ -3069,7 +3069,7 @@ static int user_write(void *vkey, void *datum, void *ptr)
buf[items++] = cpu_to_le32(usrdatum->value);
if (p->policyvers >= POLICYDB_VERSION_BOUNDARY)
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);
if (rc)
return rc;
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] SELinux: use ARRAY_SIZE
2014-06-16 20:11 [PATCH] SELinux: use ARRAY_SIZE Himangi Saraogi
@ 2014-06-17 21:40 ` Paul Moore
0 siblings, 0 replies; 2+ messages in thread
From: Paul Moore @ 2014-06-17 21:40 UTC (permalink / raw)
To: Himangi Saraogi
Cc: Stephen Smalley, Eric Paris, James Morris, selinux,
linux-security-module, linux-kernel, julia.lawall
On Tuesday, June 17, 2014 01:41:05 AM Himangi Saraogi wrote:
> 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: Himangi Saraogi <himangi774@gmail.com>
> ---
> security/selinux/ss/policydb.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
Applied, thanks.
> diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
> index 9c5cdc2..56eb65f 100644
> --- a/security/selinux/ss/policydb.c
> +++ b/security/selinux/ss/policydb.c
> @@ -2608,7 +2608,7 @@ static int mls_write_range_helper(struct mls_range *r,
> void *fp) if (!eq)
> 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);
> if (rc)
> @@ -2990,7 +2990,7 @@ static int role_write(void *vkey, void *datum, void
> *ptr) if (p->policyvers >= POLICYDB_VERSION_BOUNDARY)
> 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);
> if (rc)
> @@ -3040,7 +3040,7 @@ static int type_write(void *vkey, void *datum, void
> *ptr) } else {
> 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);
> if (rc)
> return rc;
> @@ -3069,7 +3069,7 @@ static int user_write(void *vkey, void *datum, void
> *ptr) buf[items++] = cpu_to_le32(usrdatum->value);
> if (p->policyvers >= POLICYDB_VERSION_BOUNDARY)
> 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);
> if (rc)
> return rc;
--
paul moore
www.paul-moore.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-06-17 21:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-16 20:11 [PATCH] SELinux: use ARRAY_SIZE Himangi Saraogi
2014-06-17 21:40 ` Paul Moore
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).