netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Stephen Hemminger <shemming@brocade.com>
Cc: netdev@vger.kernel.org
Subject: [iproute PATCH v4] Use ARRAY_SIZE macro everywhere
Date: Tue, 28 Jun 2016 18:42:15 +0200	[thread overview]
Message-ID: <1467132135-5472-1-git-send-email-phil@nwl.cc> (raw)
In-Reply-To: <20160327104236.0c71be5d@xeon-e3>

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

  reply	other threads:[~2016-06-28 17:08 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   ` [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       ` Phil Sutter [this message]
     [not found]       ` <5694d6b0cd854ac98abeddf04c9c32c2@HQ1WP-EXMB11.corp.brocade.com>
2016-06-29 16:18         ` [iproute PATCH v4] " 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=1467132135-5472-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).