* [iproute PATCH] Use ARRAY_SIZE macro everywhere
@ 2016-03-17 19:28 Phil Sutter
2016-03-17 19:37 ` Phil Sutter
2016-03-21 18:59 ` [iproute PATCH] " Stephen Hemminger
0 siblings, 2 replies; 8+ messages in thread
From: Phil Sutter @ 2016-03-17 19:28 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
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>
---
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [iproute PATCH] Use ARRAY_SIZE macro everywhere
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 ` [iproute PATCH v2] " Phil Sutter
2016-03-21 18:59 ` [iproute PATCH] " Stephen Hemminger
1 sibling, 1 reply; 8+ messages in thread
From: Phil Sutter @ 2016-03-17 19:37 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
On Thu, Mar 17, 2016 at 08:28:08PM +0100, Phil Sutter wrote:
> This patch was generated by the following semantic patch (a trimmed down
> version of what is shipped with Linux sources):
And it was extracted from a tree with previous commits applied, sadly
interfering with context here. Therefore it won't apply cleanly to
master. Please ignore, I will resend a fixed version.
Sorry for the noise,
Phil
^ permalink raw reply [flat|nested] 8+ messages in thread
* [iproute PATCH v2] Use ARRAY_SIZE macro everywhere
2016-03-17 19:37 ` Phil Sutter
@ 2016-03-17 19:43 ` Phil Sutter
0 siblings, 0 replies; 8+ messages in thread
From: Phil Sutter @ 2016-03-17 19:43 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [iproute PATCH] Use ARRAY_SIZE macro everywhere
2016-03-17 19:28 [iproute PATCH] Use ARRAY_SIZE macro everywhere Phil Sutter
2016-03-17 19:37 ` Phil Sutter
@ 2016-03-21 18:59 ` Stephen Hemminger
2016-03-22 15:52 ` [iproute PATCH v3] " Phil Sutter
1 sibling, 1 reply; 8+ messages in thread
From: Stephen Hemminger @ 2016-03-21 18:59 UTC (permalink / raw)
To: Phil Sutter; +Cc: netdev
On Thu, 17 Mar 2016 20:28:08 +0100
Phil Sutter <phil@nwl.cc> wrote:
> 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>
I went ahead and did some checkpatch spring cleaning to code.
This is no longer needed.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [iproute PATCH v3] Use ARRAY_SIZE macro everywhere
2016-03-21 18:59 ` [iproute PATCH] " Stephen Hemminger
@ 2016-03-22 15:52 ` Phil Sutter
2016-03-27 17:42 ` Stephen Hemminger
0 siblings, 1 reply; 8+ messages in thread
From: Phil Sutter @ 2016-03-22 15:52 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
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 onto current master to avoid merge conflicts.
Changes since v2:
- Patch recreated from scratch.
---
bridge/link.c | 2 +-
misc/nstat.c | 2 +-
misc/ss.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/bridge/link.c b/bridge/link.c
index 353e1c3da45db..b347040ccf91d 100644
--- a/bridge/link.c
+++ b/bridge/link.c
@@ -319,7 +319,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')) {
diff --git a/misc/nstat.c b/misc/nstat.c
index a9e0f20789e3c..4f3863ff99121 100644
--- a/misc/nstat.c
+++ b/misc/nstat.c
@@ -95,7 +95,7 @@ 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 192389cc82371..449c391579af1 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -666,7 +666,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--;
--
2.7.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [iproute PATCH v3] Use ARRAY_SIZE macro everywhere
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>
0 siblings, 2 replies; 8+ messages in thread
From: Stephen Hemminger @ 2016-03-27 17:42 UTC (permalink / raw)
To: Phil Sutter; +Cc: netdev
On Tue, 22 Mar 2016 16:52:53 +0100
Phil Sutter <phil@nwl.cc> wrote:
> 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 onto current master to avoid merge conflicts.
>
> Changes since v2:
> - Patch recreated from scratch.
> ---
> bridge/link.c | 2 +-
> misc/nstat.c | 2 +-
> misc/ss.c | 2 +-
> 3 files changed, 3 insertions(+), 3 deletions(-)
You need to test build after coccinelle!
nstat.c: In function ‘useless_number’:
nstat.c:98:2: warning: implicit declaration of function ‘ARRAY_SIZE’ [-Wimplicit-function-declaration]
for (i = 0; i < ARRAY_SIZE(useless_numbers); i++)
^
gcc -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wold-style-definition -Wformat=2 -O2 -I../include -DRESOLVE_HOSTNAMES -DLIBDIR=\"/usr/lib\" -DCONFDIR=\"/etc/iproute2\" -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -DHAVE_SELINUX -DHAVE_SETNS -c -o ssfilter.o ssfilter.c
gcc lnstat.o lnstat_util.o ../lib/libnetlink.a ../lib/libutil.a -lselinux -o lnstat
/tmp/ccoYmLJI.o: In function `useless_number':
nstat.c:(.text+0x40): undefined reference to `ARRAY_SIZE'
Please fix and resubmit
^ permalink raw reply [flat|nested] 8+ messages in thread
* [iproute PATCH v4] Use ARRAY_SIZE macro everywhere
2016-03-27 17:42 ` Stephen Hemminger
@ 2016-06-28 16:42 ` Phil Sutter
[not found] ` <5694d6b0cd854ac98abeddf04c9c32c2@HQ1WP-EXMB11.corp.brocade.com>
1 sibling, 0 replies; 8+ messages in thread
From: Phil Sutter @ 2016-06-28 16:42 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
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 v3:
- Rebased again.
- added missing include in misc/nstat.c.
Changes since v2:
- Patch recreated from scratch.
Changes since v1:
- Rebased onto current master to avoid merge conflicts.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
bridge/link.c | 2 +-
misc/nstat.c | 3 ++-
misc/ss.c | 2 +-
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/bridge/link.c b/bridge/link.c
index 353e1c3da45db..b347040ccf91d 100644
--- a/bridge/link.c
+++ b/bridge/link.c
@@ -319,7 +319,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')) {
diff --git a/misc/nstat.c b/misc/nstat.c
index a9e0f20789e3c..e579ce1d31586 100644
--- a/misc/nstat.c
+++ b/misc/nstat.c
@@ -30,6 +30,7 @@
#include <json_writer.h>
#include <SNAPSHOT.h>
+#include "utils.h"
int dump_zeros;
int reset_history;
@@ -95,7 +96,7 @@ 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 02be7e7407dfb..2ed9d67660b4d 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -666,7 +666,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--;
--
2.8.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
[parent not found: <5694d6b0cd854ac98abeddf04c9c32c2@HQ1WP-EXMB11.corp.brocade.com>]
end of thread, other threads:[~2016-06-29 16:18 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [iproute PATCH v2] " Phil Sutter
2016-03-21 18:59 ` [iproute PATCH] " 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
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).