All of lore.kernel.org
 help / color / mirror / Atom feed
From: <pbhagavatula@marvell.com>
To: <david.marchand@redhat.com>,
	Thomas Monjalon <thomas@monjalon.net>,
	"Ferruh Yigit" <ferruh.yigit@intel.com>,
	Andrew Rybchenko <arybchenko@solarflare.com>,
	Konstantin Ananyev <konstantin.ananyev@intel.com>,
	Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Cc: <dev@dpdk.org>, Pavan Nikhilesh <pbhagavatula@marvell.com>
Subject: [dpdk-dev] [PATCH v2 3/3] lib: use RTE_DIM to calculate array size
Date: Thu, 7 Nov 2019 08:28:22 +0530	[thread overview]
Message-ID: <20191107025823.5200-3-pbhagavatula@marvell.com> (raw)
In-Reply-To: <20191107025823.5200-1-pbhagavatula@marvell.com>

From: Pavan Nikhilesh <pbhagavatula@marvell.com>

use RTE_DIM to calculate array size.

Suggested-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
---
 lib/librte_ethdev/rte_ethdev.c        | 8 +++-----
 lib/librte_ip_frag/ip_frag_internal.c | 5 ++---
 lib/librte_port/rte_port_eventdev.c   | 4 ++--
 lib/librte_port/rte_port_eventdev.h   | 4 ----
 4 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 7743205d3..721ee694b 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -86,7 +86,7 @@ static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
 		rx_nombuf)},
 };
 
-#define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
+#define RTE_NB_STATS RTE_DIM(rte_stats_strings)
 
 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
 	{"packets", offsetof(struct rte_eth_stats, q_ipackets)},
@@ -94,15 +94,13 @@ static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
 	{"errors", offsetof(struct rte_eth_stats, q_errors)},
 };
 
-#define RTE_NB_RXQ_STATS (sizeof(rte_rxq_stats_strings) /	\
-		sizeof(rte_rxq_stats_strings[0]))
+#define RTE_NB_RXQ_STATS RTE_DIM(rte_rxq_stats_strings)
 
 static const struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
 	{"packets", offsetof(struct rte_eth_stats, q_opackets)},
 	{"bytes", offsetof(struct rte_eth_stats, q_obytes)},
 };
-#define RTE_NB_TXQ_STATS (sizeof(rte_txq_stats_strings) /	\
-		sizeof(rte_txq_stats_strings[0]))
+#define RTE_NB_TXQ_STATS RTE_DIM(rte_txq_stats_strings)
 
 #define RTE_RX_OFFLOAD_BIT2STR(_name)	\
 	{ DEV_RX_OFFLOAD_##_name, #_name }
diff --git a/lib/librte_ip_frag/ip_frag_internal.c b/lib/librte_ip_frag/ip_frag_internal.c
index 97470a872..b436a4c93 100644
--- a/lib/librte_ip_frag/ip_frag_internal.c
+++ b/lib/librte_ip_frag/ip_frag_internal.c
@@ -107,8 +107,7 @@ ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr,
 				IP_LAST_FRAG_IDX : UINT32_MAX;
 
 	/* this is the intermediate fragment. */
-	} else if ((idx = fp->last_idx) <
-		sizeof (fp->frags) / sizeof (fp->frags[0])) {
+	} else if ((idx = fp->last_idx) < RTE_DIM(fp->frags)) {
 		fp->last_idx++;
 	}
 
@@ -116,7 +115,7 @@ ip_frag_process(struct ip_frag_pkt *fp, struct rte_ip_frag_death_row *dr,
 	 * erroneous packet: either exceed max allowed number of fragments,
 	 * or duplicate first/last fragment encountered.
 	 */
-	if (idx >= sizeof (fp->frags) / sizeof (fp->frags[0])) {
+	if (idx >= RTE_DIM(fp->frags)) {
 
 		/* report an error. */
 		if (fp->key.key_len == IPV4_KEYLEN)
diff --git a/lib/librte_port/rte_port_eventdev.c b/lib/librte_port/rte_port_eventdev.c
index aa93bd3a2..fd7dac9a5 100644
--- a/lib/librte_port/rte_port_eventdev.c
+++ b/lib/librte_port/rte_port_eventdev.c
@@ -179,7 +179,7 @@ rte_port_eventdev_writer_create(void *params, int socket_id)
 	port->evt_op = conf->evt_op;
 	memset(&port->ev, 0, sizeof(port->ev));
 
-	for (i = 0; i < ARRAY_SIZE(port->ev); i++) {
+	for (i = 0; i < RTE_DIM(port->ev); i++) {
 		port->ev[i].queue_id = port->queue_id;
 		port->ev[i].sched_type = port->sched_type;
 		port->ev[i].op = port->evt_op;
@@ -386,7 +386,7 @@ rte_port_eventdev_writer_nodrop_create(void *params, int socket_id)
 	port->evt_op = conf->evt_op;
 	memset(&port->ev, 0, sizeof(port->ev));
 
-	for (i = 0; i < ARRAY_SIZE(port->ev); i++) {
+	for (i = 0; i < RTE_DIM(port->ev); i++) {
 		port->ev[i].queue_id = port->queue_id;
 		port->ev[i].sched_type = port->sched_type;
 		port->ev[i].op = port->evt_op;
diff --git a/lib/librte_port/rte_port_eventdev.h b/lib/librte_port/rte_port_eventdev.h
index acf88f4e9..966e9cdaf 100644
--- a/lib/librte_port/rte_port_eventdev.h
+++ b/lib/librte_port/rte_port_eventdev.h
@@ -9,10 +9,6 @@
 extern "C" {
 #endif
 
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 /**
  * @file
  * RTE Port Eventdev Interface
-- 
2.17.1


  parent reply	other threads:[~2019-11-07  2:59 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-28  9:09 [dpdk-dev] [PATCH 1/3] app: use RTE_DIM to calculate array size pbhagavatula
2019-10-28  9:09 ` [dpdk-dev] [PATCH 2/3] examples: " pbhagavatula
2019-10-28  9:09 ` [dpdk-dev] [PATCH 3/3] lib: " pbhagavatula
2019-10-31  9:20 ` [dpdk-dev] [PATCH 1/3] app: " David Marchand
2019-11-07  2:12   ` [dpdk-dev] [EXT] " Pavan Nikhilesh Bhagavatula
2019-11-07  2:58 ` [dpdk-dev] [PATCH v2 " pbhagavatula
2019-11-07  2:58   ` [dpdk-dev] [PATCH v2 2/3] examples: " pbhagavatula
2019-11-07  2:58   ` pbhagavatula [this message]
2019-11-07  9:08     ` [dpdk-dev] [PATCH v2 3/3] lib: " Dumitrescu, Cristian
2019-12-10 13:10   ` [dpdk-dev] [PATCH v2 1/3] app: " David Marchand
2020-01-24  4:55   ` [dpdk-dev] [PATCH v3 " pbhagavatula
2020-01-24  4:55     ` [dpdk-dev] [PATCH v3 2/3] examples: " pbhagavatula
2020-01-24  4:55     ` [dpdk-dev] [PATCH v3 3/3] lib: " pbhagavatula
2020-01-24 10:37       ` Laatz, Kevin
2020-02-05 10:22     ` [dpdk-dev] [PATCH v3 1/3] app: " David Marchand
2020-02-05 13:40       ` David Marchand

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=20191107025823.5200-3-pbhagavatula@marvell.com \
    --to=pbhagavatula@marvell.com \
    --cc=arybchenko@solarflare.com \
    --cc=cristian.dumitrescu@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=konstantin.ananyev@intel.com \
    --cc=thomas@monjalon.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.