From: Pavan Nikhilesh Date: Fri, 24 Jan 2020 04:55:44 +0000 (+0530) Subject: lib: use common macro RTE_DIM X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=9196db904b89fb8918d42a79facd798f032e2b36;p=dpdk.git lib: use common macro RTE_DIM Use RTE_DIM to calculate array size. Suggested-by: David Marchand Signed-off-by: Pavan Nikhilesh Acked-by: Cristian Dumitrescu Acked-by: Kevin Laatz Acked-by: David Marchand --- diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 9d62dc4360..774c721b34 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 97470a8725..b436a4c931 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 aa93bd3a23..fd7dac9a56 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 acf88f4e92..966e9cdafb 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 diff --git a/lib/librte_telemetry/rte_telemetry_parser_test.c b/lib/librte_telemetry/rte_telemetry_parser_test.c index 23ec7a77c9..6164ef83ec 100644 --- a/lib/librte_telemetry/rte_telemetry_parser_test.c +++ b/lib/librte_telemetry/rte_telemetry_parser_test.c @@ -463,10 +463,8 @@ rte_telemetry_parser_test(struct telemetry_impl *telemetry) }; -#define NUM_TEST_TYPES (sizeof(test_types)/sizeof(const char * const)) - uint32_t i; - for (i = 0; i < NUM_TEST_TYPES; i++) { + for (i = 0; i < RTE_DIM(test_types); i++) { TELEMETRY_LOG_INFO("%s", test_types[i]); ret = rte_telemetry_send_get_ports_and_stats_request(telemetry,