From: Phil Sutter <phil@nwl.cc>
To: Stephen Hemminger <shemming@brocade.com>
Cc: netdev@vger.kernel.org
Subject: [iproute PATCH v2] Use ARRAY_SIZE macro everywhere
Date: Thu, 17 Mar 2016 20:43:23 +0100 [thread overview]
Message-ID: <1458243803-30545-1-git-send-email-phil@nwl.cc> (raw)
In-Reply-To: <20160317193740.GC5652@orbyte.nwl.cc>
This patch was generated by the following semantic patch (a trimmed down
version of what is shipped with Linux sources):
@@
type T;
T[] E;
@@
(
- (sizeof(E)/sizeof(*E))
+ ARRAY_SIZE(E)
|
- (sizeof(E)/sizeof(E[...]))
+ ARRAY_SIZE(E)
|
- (sizeof(E)/sizeof(T))
+ ARRAY_SIZE(E)
)
The only manual adjustment was to include utils.h in misc/nstat.c to make
the macro known there.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
Changes since v1:
- Rebased upon current master to avoid merge conflicts.
---
bridge/link.c | 6 +++---
ip/ipaddress.c | 6 +++---
ip/iplink_bond_slave.c | 4 ++--
misc/nstat.c | 3 ++-
misc/ss.c | 2 +-
tc/em_meta.c | 6 +++---
tc/f_u32.c | 2 +-
7 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/bridge/link.c b/bridge/link.c
index a9b1262dfdc2d..7ecc67f34b349 100644
--- a/bridge/link.c
+++ b/bridge/link.c
@@ -69,7 +69,7 @@ static const char *hw_mode[] = {"VEB", "VEPA"};
static void print_operstate(FILE *f, __u8 state)
{
- if (state >= sizeof(oper_states)/sizeof(oper_states[0]))
+ if (state >= ARRAY_SIZE(oper_states))
fprintf(f, "state %#x ", state);
else
fprintf(f, "state %s ", oper_states[state]);
@@ -90,7 +90,7 @@ static void print_onoff(FILE *f, char *flag, __u8 val)
static void print_hwmode(FILE *f, __u16 mode)
{
- if (mode >= sizeof(hw_mode)/sizeof(hw_mode[0]))
+ if (mode >= ARRAY_SIZE(hw_mode))
fprintf(f, "hwmode %#hx ", mode);
else
fprintf(f, "hwmode %s ", hw_mode[mode]);
@@ -318,7 +318,7 @@ static int brlink_modify(int argc, char **argv)
} else if (strcmp(*argv, "state") == 0) {
NEXT_ARG();
char *endptr;
- size_t nstates = sizeof(port_states) / sizeof(*port_states);
+ size_t nstates = ARRAY_SIZE(port_states);
state = strtol(*argv, &endptr, 10);
if (!(**argv != '\0' && *endptr == '\0')) {
for (state = 0; state < nstates; state++)
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 9d254d27bc1bb..0b855a6f8c7cc 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -135,7 +135,7 @@ static const char *oper_states[] = {
static void print_operstate(FILE *f, __u8 state)
{
- if (state >= sizeof(oper_states)/sizeof(oper_states[0]))
+ if (state >= ARRAY_SIZE(oper_states))
fprintf(f, "state %#x ", state);
else {
if (brief) {
@@ -161,7 +161,7 @@ int get_operstate(const char *name)
{
int i;
- for (i = 0; i < sizeof(oper_states)/sizeof(oper_states[0]); i++)
+ for (i = 0; i < ARRAY_SIZE(oper_states); i++)
if (strcasecmp(name, oper_states[i]) == 0)
return i;
return -1;
@@ -202,7 +202,7 @@ static void print_linkmode(FILE *f, struct rtattr *tb)
{
unsigned int mode = rta_getattr_u8(tb);
- if (mode >= sizeof(link_modes) / sizeof(link_modes[0]))
+ if (mode >= ARRAY_SIZE(link_modes))
fprintf(f, "mode %d ", mode);
else
fprintf(f, "mode %s ", link_modes[mode]);
diff --git a/ip/iplink_bond_slave.c b/ip/iplink_bond_slave.c
index 2f3364ee45a54..d67793237edfc 100644
--- a/ip/iplink_bond_slave.c
+++ b/ip/iplink_bond_slave.c
@@ -26,7 +26,7 @@ static void print_slave_state(FILE *f, struct rtattr *tb)
{
unsigned int state = rta_getattr_u8(tb);
- if (state >= sizeof(slave_states) / sizeof(slave_states[0]))
+ if (state >= ARRAY_SIZE(slave_states))
fprintf(f, "state %d ", state);
else
fprintf(f, "state %s ", slave_states[state]);
@@ -43,7 +43,7 @@ static void print_slave_mii_status(FILE *f, struct rtattr *tb)
{
unsigned int status = rta_getattr_u8(tb);
- if (status >= sizeof(slave_mii_status) / sizeof(slave_mii_status[0]))
+ if (status >= ARRAY_SIZE(slave_mii_status))
fprintf(f, "mii_status %d ", status);
else
fprintf(f, "mii_status %s ", slave_mii_status[status]);
diff --git a/misc/nstat.c b/misc/nstat.c
index 22b27eba7c8f6..cc19b1cd89356 100644
--- a/misc/nstat.c
+++ b/misc/nstat.c
@@ -27,6 +27,7 @@
#include <signal.h>
#include <math.h>
#include <getopt.h>
+#include <utils.h>
#include <json_writer.h>
#include <SNAPSHOT.h>
@@ -94,7 +95,7 @@ static const char *useless_numbers[] = {
static int useless_number(const char *id)
{
int i;
- for (i=0; i<sizeof(useless_numbers)/sizeof(*useless_numbers); i++)
+ for (i=0; i<ARRAY_SIZE(useless_numbers); i++)
if (strcmp(id, useless_numbers[i]) == 0)
return 1;
return 0;
diff --git a/misc/ss.c b/misc/ss.c
index 13fcc8f661e52..0144dc10e4b45 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -668,7 +668,7 @@ static int get_slabstat(struct slabstat *s)
}
while(fgets(buf, sizeof(buf), fp) != NULL) {
int i;
- for (i=0; i<sizeof(slabstat_ids)/sizeof(slabstat_ids[0]); i++) {
+ for (i=0; i<ARRAY_SIZE(slabstat_ids); i++) {
if (memcmp(buf, slabstat_ids[i], strlen(slabstat_ids[i])) == 0) {
sscanf(buf, "%*s%d", ((int *)s) + i);
cnt--;
diff --git a/tc/em_meta.c b/tc/em_meta.c
index b64f333e5cb5b..bc871315d1d18 100644
--- a/tc/em_meta.c
+++ b/tc/em_meta.c
@@ -126,7 +126,7 @@ static struct meta_entry * lookup_meta_entry(struct bstr *kind)
{
int i;
- for (i = 0; i < (sizeof(meta_table)/sizeof(meta_table[0])); i++)
+ for (i = 0; i < ARRAY_SIZE(meta_table); i++)
if (!bstrcmp(kind, meta_table[i].kind) &&
meta_table[i].id != 0)
return &meta_table[i];
@@ -138,7 +138,7 @@ static struct meta_entry * lookup_meta_entry_byid(int id)
{
int i;
- for (i = 0; i < (sizeof(meta_table)/sizeof(meta_table[0])); i++)
+ for (i = 0; i < ARRAY_SIZE(meta_table); i++)
if (meta_table[i].id == id)
return &meta_table[i];
@@ -192,7 +192,7 @@ static void list_meta_ids(FILE *fd)
" ID Type Description\n" \
"--------------------------------------------------------");
- for (i = 0; i < (sizeof(meta_table)/sizeof(meta_table[0])); i++) {
+ for (i = 0; i < ARRAY_SIZE(meta_table); i++) {
if (meta_table[i].id == TCF_META_ID_SECTION) {
fprintf(fd, "\n%s:\n", meta_table[i].kind);
} else {
diff --git a/tc/f_u32.c b/tc/f_u32.c
index 0b97678933a62..0fb671072b793 100644
--- a/tc/f_u32.c
+++ b/tc/f_u32.c
@@ -958,7 +958,7 @@ static void show_keys(FILE *f, const struct tc_u32_key *key)
if (!show_pretty)
goto show_k;
- for (i = 0; i < sizeof(u32_pprinters) / sizeof(u32_pprinters[0]); i++) {
+ for (i = 0; i < ARRAY_SIZE(u32_pprinters); i++) {
if (u32_pprinters[i].proto == ntohs(f_proto)) {
show_k:
u32_pprinters[i].pprinter(f, key);
--
2.7.2
next prev parent reply other threads:[~2016-03-17 19:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-17 19:28 [iproute PATCH] Use ARRAY_SIZE macro everywhere Phil Sutter
2016-03-17 19:37 ` Phil Sutter
2016-03-17 19:43 ` Phil Sutter [this message]
2016-03-21 18:59 ` Stephen Hemminger
2016-03-22 15:52 ` [iproute PATCH v3] " Phil Sutter
2016-03-27 17:42 ` Stephen Hemminger
2016-06-28 16:42 ` [iproute PATCH v4] " Phil Sutter
[not found] ` <5694d6b0cd854ac98abeddf04c9c32c2@HQ1WP-EXMB11.corp.brocade.com>
2016-06-29 16:18 ` Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1458243803-30545-1-git-send-email-phil@nwl.cc \
--to=phil@nwl.cc \
--cc=netdev@vger.kernel.org \
--cc=shemming@brocade.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).