[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1458242888-28978-1-git-send-email-phil@nwl.cc>
Date: Thu, 17 Mar 2016 20:28:08 +0100
From: Phil Sutter <phil@....cc>
To: Stephen Hemminger <shemming@...cade.com>
Cc: netdev@...r.kernel.org
Subject: [iproute PATCH] Use ARRAY_SIZE macro everywhere
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@....cc>
---
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 73505d1769b6c..6f967a0329b49 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) {
color_fprintf(f, oper_state_color(state),
@@ -151,7 +151,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;
@@ -192,7 +192,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 c1026a9de6997..24d1b28602a69 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
Powered by blists - more mailing lists