[5/5] drivers/net: use RTE_DIM
Checks
Commit Message
Use RTE_DIM instead of computing directly with sizeof.
Patch automatically generated via cocci/rte_dim.cocci.
Code in base/ subdirectory manually excluded.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
drivers/net/ark/ark_pktchkr.c | 2 +-
drivers/net/ark/ark_pktgen.c | 2 +-
drivers/net/bnxt/bnxt_hwrm.c | 12 ++++++------
drivers/net/e1000/em_rxtx.c | 3 +--
drivers/net/iavf/iavf_ipsec_crypto.c | 3 +--
drivers/net/igc/igc_ethdev.c | 3 +--
drivers/net/ipn3ke/ipn3ke_tm.c | 3 +--
drivers/net/ngbe/ngbe_ethdev.c | 6 ++----
drivers/net/octeontx/octeontx_stats.h | 3 +--
drivers/net/txgbe/txgbe_ethdev.c | 9 +++------
drivers/net/txgbe/txgbe_ethdev_vf.c | 3 +--
11 files changed, 19 insertions(+), 30 deletions(-)
Comments
On 4/16/2024 4:19 PM, Stephen Hemminger wrote:
> Use RTE_DIM instead of computing directly with sizeof.
> Patch automatically generated via cocci/rte_dim.cocci.
> Code in base/ subdirectory manually excluded.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
>
Updated ones looks good to me, but I can see a few more, I don't know if
you excluded base file one intentionally,
searched as `git grep "sizeof.*\[0\]" drivers/net/`
-
drivers/net/bnxt/tf_core/cfa_tcam_mgr.h:28:#define ARRAY_SIZE(_array)
(sizeof(_array) / sizeof(_array[0]))
-
drivers/net/hinic/base/hinic_pmd_nicio.c:449: /
sizeof(hinic_hw_rx_buf_size[0]);
-
drivers/net/ice/ice_ethdev.c:330:#define ICE_NB_MBUF_XSTATS
(sizeof(ice_mbuf_strings) / sizeof(ice_mbuf_strings[0]))
-
drivers/net/i40e/i40e_ethdev.c:554:#define I40E_NB_MBUF_XSTATS
(sizeof(i40e_mbuf_strings) / sizeof(i40e_mbuf_strings[0]))
-
drivers/net/i40e/base/i40e_adminq.h:126: if (!((u32)aq_rc <
(sizeof(aq_to_posix) / sizeof((aq_to_posix)[0]))))
-
drivers/net/ipn3ke/ipn3ke_representor.c:506: /
sizeof(ipn3ke_rpst_hw_port_strings[0]))
drivers/net/ipn3ke/ipn3ke_representor.c:517: /
sizeof(ipn3ke_rpst_rxq_prio_strings[0]))
drivers/net/ipn3ke/ipn3ke_representor.c:530: /
sizeof(ipn3ke_rpst_txq_prio_strings[0]))
-
drivers/net/ixgbe/base/ixgbe_x550.c:443: for (i = 0; i <
sizeof(ixgbe_fw_map) / sizeof(ixgbe_fw_map[0]); ++i) {
drivers/net/ixgbe/base/ixgbe_x550.c:700: for (i = 0; i <
sizeof(ixgbe_fw_map) / sizeof(ixgbe_fw_map[0]); ++i) {
-
drivers/net/ixgbe/base/ixgbe_x550.c:3338: bufsz = sizeof(buf) /
sizeof(buf[0]);
-
drivers/net/mlx5/hws/mlx5dr_internal.h:52:#define ARRAY_SIZE(x)
(sizeof(x) / sizeof((x)[0]))
On Tue, 16 Apr 2024 17:29:25 +0100
Ferruh Yigit <ferruh.yigit@amd.com> wrote:
> On 4/16/2024 4:19 PM, Stephen Hemminger wrote:
> > Use RTE_DIM instead of computing directly with sizeof.
> > Patch automatically generated via cocci/rte_dim.cocci.
> > Code in base/ subdirectory manually excluded.
> >
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> >
>
> Updated ones looks good to me, but I can see a few more, I don't know if
> you excluded base file one intentionally,
> searched as `git grep "sizeof.*\[0\]" drivers/net/`
>
>
> -
> drivers/net/bnxt/tf_core/cfa_tcam_mgr.h:28:#define ARRAY_SIZE(_array)
> (sizeof(_array) / sizeof(_array[0]))
>
> -
For the drivers that choose to define and use ARRAY_SIZE() that is fine.
Since base/ directories often come from other upstream repos, I ignored those.
Something about the Intel drivers was causing warnings and the script would
not automatically change those.
On 4/16/2024 6:32 PM, Stephen Hemminger wrote:
> On Tue, 16 Apr 2024 17:29:25 +0100
> Ferruh Yigit <ferruh.yigit@amd.com> wrote:
>
>> On 4/16/2024 4:19 PM, Stephen Hemminger wrote:
>>> Use RTE_DIM instead of computing directly with sizeof.
>>> Patch automatically generated via cocci/rte_dim.cocci.
>>> Code in base/ subdirectory manually excluded.
>>>
>>> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
>>>
>>
>> Updated ones looks good to me, but I can see a few more, I don't know if
>> you excluded base file one intentionally,
>> searched as `git grep "sizeof.*\[0\]" drivers/net/`
>>
>>
>> -
>> drivers/net/bnxt/tf_core/cfa_tcam_mgr.h:28:#define ARRAY_SIZE(_array)
>> (sizeof(_array) / sizeof(_array[0]))
>>
>> -
>
> For the drivers that choose to define and use ARRAY_SIZE() that is fine.
>
ack
Although it can be updated as following, I don't think it differs
`#define ARRAY_SIZE(_array) RTE_DIM(_array)`
> Since base/ directories often come from other upstream repos, I ignored those.
>
ack
> Something about the Intel drivers was causing warnings and the script would
> not automatically change those.
>
ICE_NB_MBUF_XSTATS, I40E_NB_MBUF_XSTATS & ipn3ke_representor.c ones
seems can be updated, manually maybe?
@@ -320,7 +320,7 @@ options(const char *id)
{
unsigned int i;
- for (i = 0; i < sizeof(toptions) / sizeof(struct OPTIONS); i++) {
+ for (i = 0; i < RTE_DIM(toptions); i++) {
if (strcmp(id, toptions[i].opt) == 0)
return &toptions[i];
}
@@ -297,7 +297,7 @@ options(const char *id)
{
unsigned int i;
- for (i = 0; i < sizeof(toptions) / sizeof(struct OPTIONS); i++) {
+ for (i = 0; i < RTE_DIM(toptions); i++) {
if (strcmp(id, toptions[i].opt) == 0)
return &toptions[i];
}
@@ -72,13 +72,13 @@ const char *media_type[] = { "Unknown", "Twisted Pair",
"Direct Attached Copper", "Fiber"
};
-#define MAX_MEDIA_TYPE (sizeof(media_type) / sizeof(const char *))
+#define MAX_MEDIA_TYPE RTE_DIM(media_type)
const char *link_status_str[] = { "Down. No link or cable detected.",
"Down. No link, but a cable has been detected.", "Up.",
};
-#define MAX_LINK_STR (sizeof(link_status_str) / sizeof(const char *))
+#define MAX_LINK_STR RTE_DIM(link_status_str)
const char *fec_mode[] = {
"No active FEC",
@@ -90,13 +90,13 @@ const char *fec_mode[] = {
"FEC RS(272,257)"
};
-#define MAX_FEC_MODE (sizeof(fec_mode) / sizeof(const char *))
+#define MAX_FEC_MODE RTE_DIM(fec_mode)
const char *signal_mode[] = {
"NRZ", "PAM4", "PAM4_112"
};
-#define MAX_SIG_MODE (sizeof(signal_mode) / sizeof(const char *))
+#define MAX_SIG_MODE RTE_DIM(signal_mode)
/* multi-purpose multi-key table container.
* Add a unique entry for a new PHY attribs as per HW CAS.
@@ -226,7 +226,7 @@ struct link_speeds2_tbl {
},
};
-#define BNXT_SPEEDS2_TBL_SZ (sizeof(link_speeds2_tbl) / sizeof(*link_speeds2_tbl))
+#define BNXT_SPEEDS2_TBL_SZ RTE_DIM(link_speeds2_tbl)
/* In hwrm_phy_qcfg reports trained up speeds in link_speed(offset:0x8[31:16]) */
struct link_speeds_tbl {
@@ -269,7 +269,7 @@ struct link_speeds_tbl {
},
};
-#define BNXT_SPEEDS_TBL_SZ (sizeof(link_speeds_tbl) / sizeof(*link_speeds_tbl))
+#define BNXT_SPEEDS_TBL_SZ RTE_DIM(link_speeds_tbl)
static const char *bnxt_get_xcvr_type(uint32_t xcvr_identifier_type_tx_lpi_timer)
{
@@ -1666,8 +1666,7 @@ em_rctl_bsize(__rte_unused enum e1000_mac_type hwtyp, uint32_t *bufsz)
* ***************************************************************
*/
- for (i = 0; i != sizeof(bufsz_to_rctl) / sizeof(bufsz_to_rctl[0]);
- i++) {
+ for (i = 0; i != RTE_DIM(bufsz_to_rctl); i++) {
if (rctl_bsize >= bufsz_to_rctl[i].bufsz) {
*bufsz = bufsz_to_rctl[i].bufsz;
return bufsz_to_rctl[i].rctl;
@@ -1483,8 +1483,7 @@ iavf_ipsec_crypto_capabilities_get(void *device)
* crypto capabilities, except for last element of the array which is
* the null termination
*/
- for (i = 0; i < ((sizeof(iavf_security_capabilities) /
- sizeof(iavf_security_capabilities[0])) - 1); i++) {
+ for (i = 0; i < (RTE_DIM(iavf_security_capabilities) - 1); i++) {
iavf_security_capabilities[i].crypto_capabilities =
iavf_sctx->crypto_capabilities;
}
@@ -188,8 +188,7 @@ static const struct rte_igc_xstats_name_off rte_igc_stats_strings[] = {
offsetof(struct igc_hw_stats, icrxdmtc)},
};
-#define IGC_NB_XSTATS (sizeof(rte_igc_stats_strings) / \
- sizeof(rte_igc_stats_strings[0]))
+#define IGC_NB_XSTATS RTE_DIM(rte_igc_stats_strings)
static int eth_igc_configure(struct rte_eth_dev *dev);
static int eth_igc_link_update(struct rte_eth_dev *dev, int wait_to_complete);
@@ -67,8 +67,7 @@ struct ipn3ke_tm_shaper_params_range_type ipn3ke_tm_shaper_params_rang[] = {
{512, 1023, 15, 32768, 67108864, 134086656},
};
-#define IPN3KE_TM_SHAPER_RANGE_NUM (sizeof(ipn3ke_tm_shaper_params_rang) / \
- sizeof(struct ipn3ke_tm_shaper_params_range_type))
+#define IPN3KE_TM_SHAPER_RANGE_NUM RTE_DIM(ipn3ke_tm_shaper_params_rang)
#define IPN3KE_TM_SHAPER_COMMITTED_RATE_MAX \
(ipn3ke_tm_shaper_params_rang[IPN3KE_TM_SHAPER_RANGE_NUM - 1].high)
@@ -238,8 +238,7 @@ static const struct rte_ngbe_xstats_name_off rte_ngbe_stats_strings[] = {
HW_XSTAT_NAME(rx_xoff_packets, "rx_flow_control_xoff_packets"),
};
-#define NGBE_NB_HW_STATS (sizeof(rte_ngbe_stats_strings) / \
- sizeof(rte_ngbe_stats_strings[0]))
+#define NGBE_NB_HW_STATS RTE_DIM(rte_ngbe_stats_strings)
/* Per-queue statistics */
#define QP_XSTAT(m) {#m, offsetof(struct ngbe_hw_stats, qp[0].m)}
@@ -251,8 +250,7 @@ static const struct rte_ngbe_xstats_name_off rte_ngbe_qp_strings[] = {
QP_XSTAT(rx_qp_mc_packets),
};
-#define NGBE_NB_QP_STATS (sizeof(rte_ngbe_qp_strings) / \
- sizeof(rte_ngbe_qp_strings[0]))
+#define NGBE_NB_QP_STATS RTE_DIM(rte_ngbe_qp_strings)
static inline int32_t
ngbe_pf_reset_hw(struct ngbe_hw *hw)
@@ -36,6 +36,5 @@ struct octeontx_xstats octeontx_bgx_xstats[] = {
BGX_XSTAT(tx_pause_packets),
};
-#define NUM_BGX_XSTAT \
- (sizeof(octeontx_bgx_xstats) / sizeof(struct octeontx_xstats))
+#define NUM_BGX_XSTAT RTE_DIM(octeontx_bgx_xstats)
#endif /* __OCTEONTX_STATS_H__ */
@@ -269,8 +269,7 @@ static const struct rte_txgbe_xstats_name_off rte_txgbe_stats_strings[] = {
HW_XSTAT_NAME(rx_xoff_packets, "rx_flow_control_xoff_packets"),
};
-#define TXGBE_NB_HW_STATS (sizeof(rte_txgbe_stats_strings) / \
- sizeof(rte_txgbe_stats_strings[0]))
+#define TXGBE_NB_HW_STATS RTE_DIM(rte_txgbe_stats_strings)
/* Per-priority statistics */
#define UP_XSTAT(m) {#m, offsetof(struct txgbe_hw_stats, up[0].m)}
@@ -290,8 +289,7 @@ static const struct rte_txgbe_xstats_name_off rte_txgbe_up_strings[] = {
UP_XSTAT(tx_up_xon2off_packets),
};
-#define TXGBE_NB_UP_STATS (sizeof(rte_txgbe_up_strings) / \
- sizeof(rte_txgbe_up_strings[0]))
+#define TXGBE_NB_UP_STATS RTE_DIM(rte_txgbe_up_strings)
/* Per-queue statistics */
#define QP_XSTAT(m) {#m, offsetof(struct txgbe_hw_stats, qp[0].m)}
@@ -303,8 +301,7 @@ static const struct rte_txgbe_xstats_name_off rte_txgbe_qp_strings[] = {
QP_XSTAT(rx_qp_mc_packets),
};
-#define TXGBE_NB_QP_STATS (sizeof(rte_txgbe_qp_strings) / \
- sizeof(rte_txgbe_qp_strings[0]))
+#define TXGBE_NB_QP_STATS RTE_DIM(rte_txgbe_qp_strings)
static inline int
txgbe_is_sfp(struct txgbe_hw *hw)
@@ -112,8 +112,7 @@ static const struct rte_txgbe_xstats_name_off rte_txgbevf_stats_strings[] = {
offsetof(struct txgbevf_hw_stats, qp[7].vfmprc)}
};
-#define TXGBEVF_NB_XSTATS (sizeof(rte_txgbevf_stats_strings) / \
- sizeof(rte_txgbevf_stats_strings[0]))
+#define TXGBEVF_NB_XSTATS RTE_DIM(rte_txgbevf_stats_strings)
/*
* Negotiate mailbox API version with the PF.