avoid unnecessary use of comma op
Subsystems (2)
cover avoid unnecessary use of comma op
This series was motivated by recent thread on netdev about build with -Wcomma
Stephen Hemminger (7):
eal: replace unnecessary comma operator
ipsec: replace unnecessary comma operator
graph: replace unnecessary comma operator net/mlx4: replace unnecessary comma operators net/mlx5: replace unnecessary comma operators
test: replace unnecessary comma operators app/testpmd: replace comma operator with bracket
app/test-pmd/cmdline_flow.c | 6 ++++-- app/test/test_compressdev.c | 4 ++-- app/test/test_link_bonding_rssconf.c | 2 +- app/test/test_thash.c | 2 +- drivers/net/mlx4/mlx4_rxtx.c | 2 +- drivers/net/mlx5/linux/mlx5_os.c | 4 ++-- drivers/net/mlx5/linux/mlx5_verbs.c | 2 +- drivers/net/mlx5/mlx5_flow.c | 12 ++++++------ drivers/net/mlx5/mlx5_flow_dv.c | 2 +- drivers/net/mlx5/mlx5_nta_split.c | 4 ++-- lib/eal/common/rte_malloc.c | 4 ++-- lib/eal/linux/eal_alarm.c | 6 ++++-- lib/graph/graph_stats.c | 2 +- lib/ipsec/misc.h | 3 ++- 14 files changed, 30 insertions(+), 25 deletions(-)
Signature · 1 line
2.47.2
RFC 1/7 eal: replace unnecessary comma operator
Use of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- lib/eal/common/rte_malloc.c | 4 ++-- lib/eal/linux/eal_alarm.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-)
lib/eal/common/rte_malloc.c +2 -2
@@ -176,8 +176,8 @@ rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket) } user_size = size; - - size =RTE_CACHE_LINE_ROUNDUP (size), align =RTE_CACHE_LINE_ROUNDUP (align); + size =RTE_CACHE_LINE_ROUNDUP (size); + align =RTE_CACHE_LINE_ROUNDUP (align);/* check requested socket id and alignment matches first, and if ok, * see if we can resize block
lib/eal/linux/eal_alarm.c +4 -2
@@ -117,8 +117,10 @@ eal_alarm_callback(void *arg __rte_unused) atime.it_value.tv_sec = ap->time.tv_sec; atime.it_value.tv_nsec = ap->time.tv_usec *NS_PER_US ;/* perform borrow for subtraction if necessary */ -if (now.tv_nsec > (ap->time.tv_usec *NS_PER_US )) - atime.it_value.tv_sec--, atime.it_value.tv_nsec +=US_PER_S *NS_PER_US ; +if (now.tv_nsec > (ap->time.tv_usec *NS_PER_US )) { + atime.it_value.tv_sec--; + atime.it_value.tv_nsec +=US_PER_S *NS_PER_US ; + } atime.it_value.tv_sec -= now.tv_sec; atime.it_value.tv_nsec -= now.tv_nsec;
Signature · 1 line
2.47.2
RFC 2/7 ipsec: replace unnecessary comma operator
In reply to Stephen HemmingerUse of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- lib/ipsec/misc.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/ipsec/misc.h +2 -1
@@ -126,7 +126,8 @@ cpu_crypto_bulk(const struct rte_ipsec_session *ss,const uint32_t vnum =RTE_DIM (vec); - j =0 , n =0 ; + j =0 ; + n =0 ; vofs =0 ;for (i =0 ; i != num; i++) {
Signature · 1 line
2.47.2
RFC 3/7 graph: replace unnecessary comma operator
In reply to Stephen HemmingerUse of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- lib/graph/graph_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/graph/graph_stats.c +1 -1
@@ -253,7 +253,7 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in, *stats_in =NULL ;/* Clear the new struct cluster_node area */ - cluster =RTE_PTR_ADD (stats, stats->sz), + cluster =RTE_PTR_ADD (stats, stats->sz);memset (cluster,0 , stats->cluster_node_size);memcpy (cluster->stat.name, graph_node->node->name,RTE_NODE_NAMESIZE ); cluster->stat.id = graph_node->node->id;
Signature · 1 line
2.47.2
RFC 4/7 net/mlx4: replace unnecessary comma operators
In reply to Stephen HemmingerUse of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- drivers/net/mlx4/mlx4_rxtx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mlx4/mlx4_rxtx.c +1 -1
@@ -638,7 +638,7 @@ mlx4_tx_burst_fill_tso_hdr(struct rte_mbuf *buf, thdr.vto = sq->buf;/* New TXBB, stash the first 32bits for later use. */ pv[*pv_counter].dst = (volatile uint32_t *)thdr.to; - pv[(*pv_counter)++].val = *(uint32_t *)from, + pv[(*pv_counter)++].val = *(uint32_t *)from; from +=sizeof (uint32_t ); thdr.to +=sizeof (uint32_t ); remain_size -= txbb_avail_space +sizeof (uint32_t );
Signature · 1 line
2.47.2
RFC 5/7 net/mlx5: replace unnecessary comma operators
In reply to Stephen HemmingerUse of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- drivers/net/mlx5/linux/mlx5_os.c | 4 ++-- drivers/net/mlx5/linux/mlx5_verbs.c | 2 +- drivers/net/mlx5/mlx5_flow.c | 12 ++++++------ drivers/net/mlx5/mlx5_flow_dv.c | 2 +- drivers/net/mlx5/mlx5_nta_split.c | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +2 -2
@@ -431,8 +431,8 @@ __mlx5_discovery_misc5_cap(struct mlx5_priv *priv)DRV_LOG (INFO ,"No SW steering support" );return ; } - dv_attr.type =IBV_FLOW_ATTR_NORMAL , - dv_attr.match_mask = (void *)&matcher_mask, + dv_attr.type =IBV_FLOW_ATTR_NORMAL ; + dv_attr.match_mask = (void *)&matcher_mask; dv_attr.match_criteria_enable = (1 <<MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT ) | (1 <<MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT );
drivers/net/mlx5/linux/mlx5_verbs.c +1 -1
@@ -877,7 +877,7 @@ mlx5_txq_ibv_qp_create(struct rte_eth_dev *dev, uint16_t idx)* dev_cap.max_sge limit and will still work properly. */ qp_attr.cap.max_send_sge =1 ; - qp_attr.qp_type =IBV_QPT_RAW_PACKET , + qp_attr.qp_type =IBV_QPT_RAW_PACKET ;/* Do *NOT* enable this, completions events are managed per Tx burst. */ qp_attr.sq_sig_all =0 ; qp_attr.pd = priv->sh->cdev->pd;
drivers/net/mlx5/mlx5_flow.c +6 -6
@@ -11108,12 +11108,12 @@ flow_tunnel_add_default_miss(struct rte_eth_dev *dev, (error,ENOMEM ,RTE_FLOW_ERROR_TYPE_ACTION_CONF ,NULL ,"invalid default miss RSS" ); - ctx->action_rss.func =RTE_ETH_HASH_FUNCTION_DEFAULT , - ctx->action_rss.level =0 , - ctx->action_rss.types = priv->rss_conf.rss_hf, - ctx->action_rss.key_len = priv->rss_conf.rss_key_len, - ctx->action_rss.queue_num = priv->reta_idx_n, - ctx->action_rss.key = priv->rss_conf.rss_key, + ctx->action_rss.func =RTE_ETH_HASH_FUNCTION_DEFAULT ; + ctx->action_rss.level =0 ; + ctx->action_rss.types = priv->rss_conf.rss_hf; + ctx->action_rss.key_len = priv->rss_conf.rss_key_len; + ctx->action_rss.queue_num = priv->reta_idx_n; + ctx->action_rss.key = priv->rss_conf.rss_key; ctx->action_rss.queue = ctx->queue;if (!priv->reta_idx_n || !priv->rxqs_n)return rte_flow_error_set
drivers/net/mlx5/mlx5_flow_dv.c +1 -1
@@ -18804,7 +18804,7 @@ flow_dv_create_mtr_tbls(struct rte_eth_dev *dev, } }/* Create default matcher in drop table. */ - matcher.tbl = mtrmng->drop_tbl[domain], + matcher.tbl = mtrmng->drop_tbl[domain]; tbl_data =container_of (mtrmng->drop_tbl[domain], struct mlx5_flow_tbl_data_entry, tbl);if (!mtrmng->def_matcher[domain]) {
drivers/net/mlx5/mlx5_nta_split.c +2 -2
@@ -345,8 +345,8 @@ flow_nta_mreg_create_cb(void *tool_ctx, void *cb_ctx)/* (match REG 'tag') or all. */ items[1 ].type =RTE_FLOW_ITEM_TYPE_END ;/* (Mark) or void + copy to Rx meta + jump to the MREG_ACT_TABLE_GROUP. */ - actions[1 ].type =RTE_FLOW_ACTION_TYPE_MODIFY_FIELD , - actions[1 ].conf = &rx_meta, + actions[1 ].type =RTE_FLOW_ACTION_TYPE_MODIFY_FIELD ; + actions[1 ].conf = &rx_meta; actions[2 ].type =RTE_FLOW_ACTION_TYPE_JUMP ; actions[2 ].conf = &jump; actions[3 ].type =RTE_FLOW_ACTION_TYPE_END ;
Signature · 1 line
2.47.2
RFC 6/7 test: replace unnecessary comma operators
In reply to Stephen HemmingerUse of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- app/test/test_compressdev.c | 4 ++-- app/test/test_link_bonding_rssconf.c | 2 +- app/test/test_thash.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
app/test/test_compressdev.c +2 -2
@@ -273,7 +273,7 @@ testsuite_setup(void)/* Initializes default values for compress/decompress xforms */ ts_params->def_comp_xform->type =RTE_COMP_COMPRESS ; - ts_params->def_comp_xform->compress.algo =RTE_COMP_ALGO_DEFLATE , + ts_params->def_comp_xform->compress.algo =RTE_COMP_ALGO_DEFLATE ; ts_params->def_comp_xform->compress.deflate.huffman =RTE_COMP_HUFFMAN_DEFAULT ; ts_params->def_comp_xform->compress.level =RTE_COMP_LEVEL_PMD_DEFAULT ;
@@ -281,7 +281,7 @@ testsuite_setup(void) ts_params->def_comp_xform->compress.window_size =DEFAULT_WINDOW_SIZE ; ts_params->def_decomp_xform->type =RTE_COMP_DECOMPRESS ; - ts_params->def_decomp_xform->decompress.algo =RTE_COMP_ALGO_DEFLATE , + ts_params->def_decomp_xform->decompress.algo =RTE_COMP_ALGO_DEFLATE ; ts_params->def_decomp_xform->decompress.chksum =RTE_COMP_CHECKSUM_NONE ; ts_params->def_decomp_xform->decompress.window_size =DEFAULT_WINDOW_SIZE ;
app/test/test_link_bonding_rssconf.c +1 -1
@@ -384,7 +384,7 @@ test_propagate(void) }memset (bond_rss_key, i,sizeof (bond_rss_key)); - bond_rss_conf.rss_hf = default_rss_hf, + bond_rss_conf.rss_hf = default_rss_hf; bond_rss_conf.rss_key = bond_rss_key; bond_rss_conf.rss_key_len =40 ;
app/test/test_thash.c +1 -1
@@ -910,7 +910,7 @@ test_adjust_tuple_mult_reta(void) {uint32_t i, j, np, nt; - nt =0 , np =0 ; + nt =0 ; np =0 ;for (i =0 ; i <CHAR_BIT ; i++) {for (j =6 ; j <=RTE_THASH_RETA_SZ_MAX - i; j++) { np += (test_adjust_tuple_mb (j, i) ==0 );
Signature · 1 line
2.47.2
RFC 7/7 app/testpmd: replace comma operator with bracket
In reply to Stephen HemmingerUse while with brackets in favor of comma operator.
--- app/test-pmd/cmdline_flow.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
app/test-pmd/cmdline_flow.c +4 -2
@@ -8333,8 +8333,10 @@ parse_prefix(struct context *ctx, const struct token *token,if (!ctx->object)return len; extra -= u; -while (u--) - (v <<=1 , v |=1 ); +while (u--) { + v <<=1 ; + v |=1 ; + } v <<= extra;if (!arg_entry_bf_fill (ctx->object, v, arg) || !arg_entry_bf_fill (ctx->objmask,-1 , arg))
Signature · 1 line
2.47.2
v2 cover Enable warnings about use of comma operator
In reply to Stephen HemmingerThis series was motivated by recent thread on netdev about build with -Wcomma in clang. This warning catches code that uses comma where a semi-colon is a better choice.
v2 - rebase and drop any driver related changes
Stephen Hemminger (6):
eal: replace unnecessary comma operator
ipsec: replace unnecessary comma operator
graph: replace unnecessary comma operator
test: replace unnecessary comma operators app/testpmd: replace comma operator with bracket
config: enable comma warnings
app/test-pmd/cmdline_flow.c | 6 ++++-- app/test-pmd/config.c | 10 ++++++---- app/test/test_compressdev.c | 4 ++-- app/test/test_link_bonding_rssconf.c | 2 +- app/test/test_thash.c | 2 +- config/meson.build | 1 + drivers/meson.build | 2 +- lib/eal/common/rte_malloc.c | 4 ++-- lib/eal/linux/eal_alarm.c | 6 ++++-- lib/graph/graph_stats.c | 2 +- lib/ipsec/misc.h | 3 ++- 11 files changed, 25 insertions(+), 17 deletions(-)
--
2.47.2
PATCH v2 1/6 eal: replace unnecessary comma operator
Use of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- lib/eal/common/rte_malloc.c | 4 ++-- lib/eal/linux/eal_alarm.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-)
lib/eal/common/rte_malloc.c +2 -2
@@ -202,8 +202,8 @@ rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket) } user_size = size; - - size =RTE_CACHE_LINE_ROUNDUP (size), align =RTE_CACHE_LINE_ROUNDUP (align); + size =RTE_CACHE_LINE_ROUNDUP (size); + align =RTE_CACHE_LINE_ROUNDUP (align);/* check requested socket id and alignment matches first, and if ok, * see if we can resize block
lib/eal/linux/eal_alarm.c +4 -2
@@ -125,8 +125,10 @@ eal_alarm_callback(void *arg __rte_unused) atime.it_value.tv_sec = ap->time.tv_sec; atime.it_value.tv_nsec = ap->time.tv_usec *NS_PER_US ;/* perform borrow for subtraction if necessary */ -if (now.tv_nsec > (ap->time.tv_usec *NS_PER_US )) - atime.it_value.tv_sec--, atime.it_value.tv_nsec +=US_PER_S *NS_PER_US ; +if (now.tv_nsec > (ap->time.tv_usec *NS_PER_US )) { + atime.it_value.tv_sec--; + atime.it_value.tv_nsec +=US_PER_S *NS_PER_US ; + } atime.it_value.tv_sec -= now.tv_sec; atime.it_value.tv_nsec -= now.tv_nsec;
Signature · 1 line
2.47.2
RE: [PATCH v2 1/6] eal: replace unnecessary comma operator
Quoted 34 lines
Use of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
Signed-off-by Stephen Hemminger <[email protected]>--- lib/eal/common/rte_malloc.c | 4 ++-- lib/eal/linux/eal_alarm.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-)lib/eal/common/rte_malloc.c +2
-2@@ -202,8 +202,8 @@ rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket) } user_size = size; - - size =RTE_CACHE_LINE_ROUNDUP (size), align =RTE_CACHE_LINE_ROUNDUP (align); + size =RTE_CACHE_LINE_ROUNDUP (size); + align =RTE_CACHE_LINE_ROUNDUP (align);/* check requested socket id and alignment matches first, and if ok, * see if we can resize block lib/eal/linux/eal_alarm.c +0
-0@@ -125,8 +125,10 @@ eal_alarm_callback(void *arg __rte_unused) atime.it_value.tv_sec = ap->time.tv_sec; atime.it_value.tv_nsec = ap->time.tv_usec *NS_PER_US ;/* perform borrow for subtraction if necessary */
lib/eal/linux/eal_alarm.c eal_alarm_callback(void *arg __rte_unused)
Quoted 10 lines
lib/eal/linux/eal_alarm.c +4
-3-if (now.tv_nsec > (ap->time.tv_usec *NS_PER_US )) - atime.it_value.tv_sec--, atime.it_value.tv_nsec +=US_PER_S *NS_PER_US ; +if (now.tv_nsec > (ap->time.tv_usec *NS_PER_US )) { + atime.it_value.tv_sec--; + atime.it_value.tv_nsec +=US_PER_S *NS_PER_US ; + } atime.it_value.tv_sec -= now.tv_sec; atime.it_value.tv_nsec -= now.tv_nsec; --
Quoted 1 line
2.47.2
Re: [PATCH v2 1/6] eal: replace unnecessary comma operator
In reply to Stephen HemmingerQuoted 8 lines · Stephen Hemminger
Use of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
Signed-off-by Stephen Hemminger <[email protected]>--- lib/eal/common/rte_malloc.c | 4 ++-- lib/eal/linux/eal_alarm.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-)
PATCH v2 2/6 ipsec: replace unnecessary comma operator
In reply to Stephen HemmingerUse of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- lib/ipsec/misc.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/ipsec/misc.h +2 -1
@@ -126,7 +126,8 @@ cpu_crypto_bulk(const struct rte_ipsec_session *ss,const uint32_t vnum =RTE_DIM (vec); - j =0 , n =0 ; + j =0 ; + n =0 ; vofs =0 ;for (i =0 ; i != num; i++) {
Signature · 1 line
2.47.2
RE: [PATCH v2 2/6] ipsec: replace unnecessary comma operator
Quoted 23 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Thursday, August 14, 2025 10:29 PM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Konstantin Ananyev <[email protected]>; Vladimir Medvedkin <[email protected]>
Subject: [PATCH v2 2/6] ipsec: replace unnecessary comma operatorUse of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
Signed-off-by Stephen Hemminger <[email protected]>--- lib/ipsec/misc.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)lib/ipsec/misc.h +0
-0
lib/ipsec/misc.h cpu_crypto_bulk(const struct rte_ipsec_session *ss,
Quoted 10 lines
lib/ipsec/misc.h +2
-2@@ -126,7 +126,8 @@ cpu_crypto_bulk(const struct rte_ipsec_session *ss,const uint32_t vnum =RTE_DIM (vec); - j =0 , n =0 ; + j =0 ; + n =0 ; vofs =0 ;for (i =0 ; i != num; i++) { --
Quoted 1 line
2.47.2
Re: [PATCH v2 2/6] ipsec: replace unnecessary comma operator
In reply to Stephen HemmingerQuoted 13 lines · Stephen Hemminger
Use of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
Signed-off-by Stephen Hemminger <[email protected]>--- lib/ipsec/misc.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)lib/ipsec/misc.h +0
-0
lib/ipsec/misc.h cpu_crypto_bulk(const struct rte_ipsec_session *ss, · line 133
Quoted 9 lines
lib/ipsec/misc.h +2
-1@@ -126,7 +126,8 @@ cpu_crypto_bulk(const struct rte_ipsec_session *ss,const uint32_t vnum =RTE_DIM (vec); - j =0 , n =0 ; + j =0 ; + n =0 ; vofs =0 ;for (i =0 ; i != num; i++) {
A better fix here is to move the assignments up to where the variables are defined just 9 lines earlier, rather than wasting code lines by assigning to zero later on!
RE: [PATCH v2 2/6] ipsec: replace unnecessary comma operator
Quoted 10 lines
From: Bruce Richardson [mailto:[email protected]]
Sent: Monday, 18 August 2025 10.01Quoted 5 lines · Stephen Hemminger
Use of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
Signed-off-by Stephen Hemminger <[email protected]>---
Quoted 10 lines
lib/ipsec/misc.h cpu_crypto_bulk(const struct rte_ipsec_session *ss, · line 132
Quoted 6 lines
lib/ipsec/misc.h +2
-1- j =0 , n =0 ; + j =0 ; + n =0 ; vofs =0 ;for (i =0 ; i != num; i++) {A better fix here is to move the assignments up to where the variables are defined just 9 lines earlier, rather than wasting code lines by assigning to zero later on!
+1
PATCH v2 3/6 graph: replace unnecessary comma operator
In reply to Stephen HemmingerUse of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- lib/graph/graph_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/graph/graph_stats.c +1 -1
@@ -254,7 +254,7 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in, *stats_in =NULL ;/* Clear the new struct cluster_node area */ - cluster =RTE_PTR_ADD (stats, stats->sz), + cluster =RTE_PTR_ADD (stats, stats->sz);memset (cluster,0 , stats->cluster_node_size);memcpy (cluster->stat.name, graph_node->node->name,RTE_NODE_NAMESIZE ); cluster->stat.id = graph_node->node->id;
Signature · 1 line
2.47.2
RE: [PATCH v2 3/6] graph: replace unnecessary comma operator
Quoted 15 lines
Use of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
Signed-off-by Stephen Hemminger <[email protected]>--- lib/graph/graph_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/graph/graph_stats.c +0
-0
lib/graph/graph_stats.c stats_mem_populate(struct rte_graph_cluster_stats **stats_in,
Quoted 9 lines
lib/graph/graph_stats.c +1
-2@@ -254,7 +254,7 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in, *stats_in =NULL ;/* Clear the new struct cluster_node area */ - cluster =RTE_PTR_ADD (stats, stats->sz), + cluster =RTE_PTR_ADD (stats, stats->sz);memset (cluster,0 , stats->cluster_node_size);memcpy (cluster->stat.name, graph_node->node->name,RTE_NODE_NAMESIZE ); cluster->stat.id = graph_node->node->id; --
Quoted 2 lines
2.47.2
Re: [PATCH v2 3/6] graph: replace unnecessary comma operator
In reply to Stephen HemmingerQuoted 13 lines · Stephen Hemminger
Use of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
Signed-off-by Stephen Hemminger <[email protected]>--- lib/graph/graph_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/graph/graph_stats.c +0
-0
lib/graph/graph_stats.c stats_mem_populate(struct rte_graph_cluster_stats **stats_in, · line 260
Quoted 8 lines
lib/graph/graph_stats.c +1
-1@@ -254,7 +254,7 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in, *stats_in =NULL ;/* Clear the new struct cluster_node area */ - cluster =RTE_PTR_ADD (stats, stats->sz), + cluster =RTE_PTR_ADD (stats, stats->sz);memset (cluster,0 , stats->cluster_node_size);memcpy (cluster->stat.name, graph_node->node->name,RTE_NODE_NAMESIZE ); cluster->stat.id = graph_node->node->id;
PATCH v2 4/6 test: replace unnecessary comma operators
In reply to Stephen HemmingerUse of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- app/test/test_compressdev.c | 4 ++-- app/test/test_link_bonding_rssconf.c | 2 +- app/test/test_thash.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
app/test/test_compressdev.c +2 -2
@@ -273,7 +273,7 @@ testsuite_setup(void)/* Initializes default values for compress/decompress xforms */ ts_params->def_comp_xform->type =RTE_COMP_COMPRESS ; - ts_params->def_comp_xform->compress.algo =RTE_COMP_ALGO_DEFLATE , + ts_params->def_comp_xform->compress.algo =RTE_COMP_ALGO_DEFLATE ; ts_params->def_comp_xform->compress.deflate.huffman =RTE_COMP_HUFFMAN_DEFAULT ; ts_params->def_comp_xform->compress.level =RTE_COMP_LEVEL_PMD_DEFAULT ;
@@ -281,7 +281,7 @@ testsuite_setup(void) ts_params->def_comp_xform->compress.window_size =DEFAULT_WINDOW_SIZE ; ts_params->def_decomp_xform->type =RTE_COMP_DECOMPRESS ; - ts_params->def_decomp_xform->decompress.algo =RTE_COMP_ALGO_DEFLATE , + ts_params->def_decomp_xform->decompress.algo =RTE_COMP_ALGO_DEFLATE ; ts_params->def_decomp_xform->decompress.chksum =RTE_COMP_CHECKSUM_NONE ; ts_params->def_decomp_xform->decompress.window_size =DEFAULT_WINDOW_SIZE ;
app/test/test_link_bonding_rssconf.c +1 -1
@@ -384,7 +384,7 @@ test_propagate(void) }memset (bond_rss_key, i,sizeof (bond_rss_key)); - bond_rss_conf.rss_hf = default_rss_hf, + bond_rss_conf.rss_hf = default_rss_hf; bond_rss_conf.rss_key = bond_rss_key; bond_rss_conf.rss_key_len =40 ;
app/test/test_thash.c +1 -1
@@ -910,7 +910,7 @@ test_adjust_tuple_mult_reta(void) {uint32_t i, j, np, nt; - nt =0 , np =0 ; + nt =0 ; np =0 ;for (i =0 ; i <CHAR_BIT ; i++) {for (j =6 ; j <=RTE_THASH_RETA_SZ_MAX - i; j++) { np += (test_adjust_tuple_mb (j, i) ==0 );
Signature · 1 line
2.47.2
RE: [PATCH v2 4/6] test: replace unnecessary comma operators
Quoted 51 lines
Use of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
Signed-off-by Stephen Hemminger <[email protected]>--- app/test/test_compressdev.c | 4 ++-- app/test/test_link_bonding_rssconf.c | 2 +- app/test/test_thash.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)app/test/test_compressdev.c +2
-2@@ -273,7 +273,7 @@ testsuite_setup(void)/* Initializes default values for compress/decompress xforms */ ts_params->def_comp_xform->type =RTE_COMP_COMPRESS ; - ts_params->def_comp_xform->compress.algo =RTE_COMP_ALGO_DEFLATE , + ts_params->def_comp_xform->compress.algo =RTE_COMP_ALGO_DEFLATE ; ts_params->def_comp_xform->compress.deflate.huffman =RTE_COMP_HUFFMAN_DEFAULT ; ts_params->def_comp_xform->compress.level =RTE_COMP_LEVEL_PMD_DEFAULT ;@@ -281,7 +281,7 @@ testsuite_setup(void) ts_params->def_comp_xform->compress.window_size =DEFAULT_WINDOW_SIZE ; ts_params->def_decomp_xform->type =RTE_COMP_DECOMPRESS ; - ts_params->def_decomp_xform->decompress.algo =RTE_COMP_ALGO_DEFLATE , + ts_params->def_decomp_xform->decompress.algo =RTE_COMP_ALGO_DEFLATE ; ts_params->def_decomp_xform->decompress.chksum =RTE_COMP_CHECKSUM_NONE ; ts_params->def_decomp_xform->decompress.window_size =DEFAULT_WINDOW_SIZE ;app/test/test_link_bonding_rssconf.c +1
-1@@ -384,7 +384,7 @@ test_propagate(void) }memset (bond_rss_key, i,sizeof (bond_rss_key)); - bond_rss_conf.rss_hf = default_rss_hf, + bond_rss_conf.rss_hf = default_rss_hf; bond_rss_conf.rss_key = bond_rss_key; bond_rss_conf.rss_key_len =40 ;app/test/test_thash.c +0
-0
app/test/test_thash.c test_adjust_tuple_mult_reta(void)
Quoted 9 lines
app/test/test_thash.c +1
-2@@ -910,7 +910,7 @@ test_adjust_tuple_mult_reta(void) {uint32_t i, j, np, nt; - nt =0 , np =0 ; + nt =0 ; np =0 ;for (i =0 ; i <CHAR_BIT ; i++) {for (j =6 ; j <=RTE_THASH_RETA_SZ_MAX - i; j++) { np += (test_adjust_tuple_mb (j, i) ==0 ); --
Quoted 1 line
2.47.2
Re: [PATCH v2 4/6] test: replace unnecessary comma operators
In reply to Stephen HemmingerQuoted 10 lines · Stephen Hemminger
Use of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
Signed-off-by Stephen Hemminger <[email protected]>--- app/test/test_compressdev.c | 4 ++-- app/test/test_link_bonding_rssconf.c | 2 +- app/test/test_thash.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
One suggested improvement for the last update below.
Quoted 40 lines
app/test/test_compressdev.c +2
-2@@ -273,7 +273,7 @@ testsuite_setup(void)/* Initializes default values for compress/decompress xforms */ ts_params->def_comp_xform->type =RTE_COMP_COMPRESS ; - ts_params->def_comp_xform->compress.algo =RTE_COMP_ALGO_DEFLATE , + ts_params->def_comp_xform->compress.algo =RTE_COMP_ALGO_DEFLATE ; ts_params->def_comp_xform->compress.deflate.huffman =RTE_COMP_HUFFMAN_DEFAULT ; ts_params->def_comp_xform->compress.level =RTE_COMP_LEVEL_PMD_DEFAULT ;@@ -281,7 +281,7 @@ testsuite_setup(void) ts_params->def_comp_xform->compress.window_size =DEFAULT_WINDOW_SIZE ; ts_params->def_decomp_xform->type =RTE_COMP_DECOMPRESS ; - ts_params->def_decomp_xform->decompress.algo =RTE_COMP_ALGO_DEFLATE , + ts_params->def_decomp_xform->decompress.algo =RTE_COMP_ALGO_DEFLATE ; ts_params->def_decomp_xform->decompress.chksum =RTE_COMP_CHECKSUM_NONE ; ts_params->def_decomp_xform->decompress.window_size =DEFAULT_WINDOW_SIZE ;app/test/test_link_bonding_rssconf.c +1
-1@@ -384,7 +384,7 @@ test_propagate(void) }memset (bond_rss_key, i,sizeof (bond_rss_key)); - bond_rss_conf.rss_hf = default_rss_hf, + bond_rss_conf.rss_hf = default_rss_hf; bond_rss_conf.rss_key = bond_rss_key; bond_rss_conf.rss_key_len =40 ;app/test/test_thash.c +0
-0
app/test/test_thash.c test_adjust_tuple_mult_reta(void) · line 913
Quoted 5 lines
app/test/test_thash.c +1
-1@@ -910,7 +910,7 @@ test_adjust_tuple_mult_reta(void) {uint32_t i, j, np, nt; - nt =0 , np =0 ; + nt =0 ; np =0 ;
Again, I think we should just assign to zero these where they are defined.
Quoted 6 lines
app/test/test_thash.c +0
-0for (i =0 ; i <CHAR_BIT ; i++) {for (j =6 ; j <=RTE_THASH_RETA_SZ_MAX - i; j++) { np += (test_adjust_tuple_mb (j, i) ==0 );Signature · 1 line
2.47.2
PATCH v2 5/6 app/testpmd: replace comma operator with bracket
In reply to Stephen HemmingerUse while with brackets in favor of comma operator.
In flow print replace with temporary variable.
--- app/test-pmd/cmdline_flow.c | 6 ++++-- app/test-pmd/config.c | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-)
app/test-pmd/cmdline_flow.c +4 -2
@@ -8333,8 +8333,10 @@ parse_prefix(struct context *ctx, const struct token *token,if (!ctx->object)return len; extra -= u; -while (u--) - (v <<=1 , v |=1 ); +while (u--) { + v <<=1 ; + v |=1 ; + } v <<= extra;if (!arg_entry_bf_fill (ctx->object, v, arg) || !arg_entry_bf_fill (ctx->objmask,-1 , arg))
app/test-pmd/config.c +6 -4
@@ -1497,7 +1497,7 @@ port_flow_complain(struct rte_flow_error *error) [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action", };const char *errstr; -char buf[32 ]; +char cause_buf[32 ] ="" ;int err = rte_errno; if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
@@ -1505,10 +1505,12 @@ port_flow_complain(struct rte_flow_error *error) errstr ="unknown type" ; else errstr = errstrlist[error->type]; + +if (error->cause) +snprintf (cause_buf,sizeof (cause_buf),"cause: %p, " , error->cause); +fprintf (stderr,"%s(): Caught PMD error type %d (%s): %s%s: %s\n" , - __func__, error->type, errstr, - error->cause ? (snprintf (buf,sizeof (buf),"cause: %p, " , - error->cause), buf) :"" , + __func__, error->type, errstr, cause_buf, error->message ? error->message :"(no stated reason)" ,rte_strerror (err));
Signature · 1 line
2.47.2
Re: [PATCH v2 5/6] app/testpmd: replace comma operator with bracket
Quoted 10 lines · Stephen Hemminger
Use while with brackets in favor of comma operator.
In flow print replace with temporary variable.
Signed-off-by Stephen Hemminger <[email protected]>--- app/test-pmd/cmdline_flow.c | 6 ++++-- app/test-pmd/config.c | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-)
PATCH v2 6/6 config: enable comma warnings
In reply to Stephen HemmingerClang (3.9 or later) has a -Wcomma that emits warnings for questionable uses of the comma operator.
Don't enable it for drivers since many drivers still use comma operator unnecessarily.
--- config/meson.build | 1 + drivers/meson.build | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
config/meson.build +1 -0
@@ -313,6 +313,7 @@ endif global_cflags = [ # additional warnings in alphabetical order '-Wcast-qual', + '-Wcomma', '-Wdeprecated', '-Wformat', '-Wformat-nonliteral',
drivers/meson.build +1 -1
@@ -59,7 +59,7 @@ default_cflags = machine_args default_cflags += ['-DALLOW_EXPERIMENTAL_API'] default_cflags += ['-DALLOW_INTERNAL_API'] -warning_disable_cflags = ['-Wno-format-truncation', '-Wno-address-of-packed-member'] +warning_disable_cflags = ['-Wno-format-truncation', '-Wno-address-of-packed-member', '-Wno-comma'] foreach cflag:warning_disable_cflags if cc.has_argument(cflag) default_cflags += cflag
Signature · 1 line
2.47.2
RE: [PATCH v2 6/6] config: enable comma warnings
Quoted 31 lines
Clang (3.9 or later) has a -Wcomma that emits warnings for questionable uses of the comma operator.
Don't enable it for drivers since many drivers still use comma operator unnecessarily.
Signed-off-by Stephen Hemminger <[email protected]>--- config/meson.build | 1 + drivers/meson.build | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)config/meson.build +1
-0@@ -313,6 +313,7 @@ endif global_cflags = [ # additional warnings in alphabetical order '-Wcast-qual', + '-Wcomma', '-Wdeprecated', '-Wformat', '-Wformat-nonliteral',drivers/meson.build +0
-0
drivers/meson.build default_cflags = machine_args
Quoted 9 lines
drivers/meson.build +1
-2@@ -59,7 +59,7 @@ default_cflags = machine_args default_cflags += ['-DALLOW_EXPERIMENTAL_API'] default_cflags += ['-DALLOW_INTERNAL_API'] -warning_disable_cflags = ['-Wno-format-truncation', '-Wno-address-of-packed-member'] +warning_disable_cflags = ['-Wno-format-truncation', '-Wno-address-of-packed-member', '-Wno-comma'] foreach cflag:warning_disable_cflags if cc.has_argument(cflag) default_cflags += cflag --
Quoted 1 line
2.47.2
Re: [PATCH v2 0/6] Enable warnings about use of comma operator
In reply to Stephen HemmingerQuoted 29 lines · Stephen Hemminger
This series was motivated by recent thread on netdev about build with -Wcomma in clang. This warning catches code that uses comma where a semi-colon is a better choice.
v2 - rebase and drop any driver related changes
Stephen Hemminger (6):
eal: replace unnecessary comma operator
ipsec: replace unnecessary comma operator
graph: replace unnecessary comma operator
test: replace unnecessary comma operators app/testpmd: replace comma operator with bracket
config: enable comma warningsapp/test-pmd/cmdline_flow.c | 6 ++++-- app/test-pmd/config.c | 10 ++++++---- app/test/test_compressdev.c | 4 ++-- app/test/test_link_bonding_rssconf.c | 2 +- app/test/test_thash.c | 2 +- config/meson.build | 1 + drivers/meson.build | 2 +- lib/eal/common/rte_malloc.c | 4 ++-- lib/eal/linux/eal_alarm.c | 6 ++++-- lib/graph/graph_stats.c | 2 +- lib/ipsec/misc.h | 3 ++- 11 files changed, 25 insertions(+), 17 deletions(-)--
2.47.2
RE: [PATCH v2 0/6] Enable warnings about use of comma operator
In reply to Stephen HemmingerQuoted 6 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Thursday, 14 August 2025 23.29This series was motivated by recent thread on netdev about build with -Wcomma in clang. This warning catches code that uses comma where a semi-colon is a better choice.
Overall, I agree that using semicolon is better for consistency is most places, but using commas in some loops - e.g. "for (dst=,src=; condition; dst+=, src+=)" - might be more readable than the alternative.
Stephen, I'm interested in the discussion about this, can you please post a link to the thread on the netdev mailing list?
Re: [PATCH v2 0/6] Enable warnings about use of comma operator
Quoted 8 lines · On Fri, 15 Aug 2025 08:40:58 +0200 Morten Brørup <[email protected]>…
Quoted 6 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Thursday, 14 August 2025 23.29This series was motivated by recent thread on netdev about build with -Wcomma in clang. This warning catches code that uses comma where a semi-colon is a better choice.
Overall, I agree that using semicolon is better for consistency is most places, but using commas in some loops - e.g. "for (dst=,src=; condition; dst+=, src+=)" - might be more readable than the alternative.
The compiler only warns for standalone statements, it handles the case of for(i=0,j=0;i < n; i++, j++) with out warnings.
Quoted 3 lines
Stephen, I'm interested in the discussion about this, can you please post a link to the thread on the netdev mailing list?
There is not a single thread, Simon sent patches for Intel and Nvidia drivers that have been merged.
https://marc.info/?l=linux-netdev&m=170280627225075&w=2
v3 cover avoid unnecessary use of comma operator
In reply to Stephen HemmingerClang has ability to detect suspicious use of comma operator where a semicolon would have the same effect.
Easy enough to fix in DPDK code.
V3 - fix examples as well
Stephen Hemminger (7):
eal: replace unnecessary comma operator
ipsec: replace unnecessary comma operator
graph: replace unnecessary comma operator
test: replace unnecessary comma operators app/testpmd: replace comma operator with bracket
examples: remove unnecessary use of comma operator
config: enable comma warnings
app/test-pmd/cmdline_flow.c | 6 ++++-- app/test-pmd/config.c | 10 ++++++---- app/test/test_compressdev.c | 4 ++-- app/test/test_link_bonding_rssconf.c | 2 +- app/test/test_thash.c | 2 +- config/meson.build | 1 + drivers/meson.build | 2 +- examples/l2fwd-event/l2fwd_event_generic.c | 2 +- examples/l3fwd/l3fwd_event_generic.c | 2 +- lib/eal/common/rte_malloc.c | 4 ++-- lib/eal/linux/eal_alarm.c | 6 ++++-- lib/graph/graph_stats.c | 2 +- lib/ipsec/misc.h | 3 ++- 13 files changed, 27 insertions(+), 19 deletions(-)
--
2.47.2
PATCH v3 1/7 eal: replace unnecessary comma operator
Use of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- lib/eal/common/rte_malloc.c | 4 ++-- lib/eal/linux/eal_alarm.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-)
lib/eal/common/rte_malloc.c +2 -2
@@ -202,8 +202,8 @@ rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket) } user_size = size; - - size =RTE_CACHE_LINE_ROUNDUP (size), align =RTE_CACHE_LINE_ROUNDUP (align); + size =RTE_CACHE_LINE_ROUNDUP (size); + align =RTE_CACHE_LINE_ROUNDUP (align);/* check requested socket id and alignment matches first, and if ok, * see if we can resize block
lib/eal/linux/eal_alarm.c +4 -2
@@ -125,8 +125,10 @@ eal_alarm_callback(void *arg __rte_unused) atime.it_value.tv_sec = ap->time.tv_sec; atime.it_value.tv_nsec = ap->time.tv_usec *NS_PER_US ;/* perform borrow for subtraction if necessary */ -if (now.tv_nsec > (ap->time.tv_usec *NS_PER_US )) - atime.it_value.tv_sec--, atime.it_value.tv_nsec +=US_PER_S *NS_PER_US ; +if (now.tv_nsec > (ap->time.tv_usec *NS_PER_US )) { + atime.it_value.tv_sec--; + atime.it_value.tv_nsec +=US_PER_S *NS_PER_US ; + } atime.it_value.tv_sec -= now.tv_sec; atime.it_value.tv_nsec -= now.tv_nsec;
Signature · 1 line
2.47.2
PATCH v3 2/7 ipsec: replace unnecessary comma operator
In reply to Stephen HemmingerUse of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- lib/ipsec/misc.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/ipsec/misc.h +2 -1
@@ -126,7 +126,8 @@ cpu_crypto_bulk(const struct rte_ipsec_session *ss,const uint32_t vnum =RTE_DIM (vec); - j =0 , n =0 ; + j =0 ; + n =0 ; vofs =0 ;for (i =0 ; i != num; i++) {
Signature · 1 line
2.47.2
PATCH v3 3/7 graph: replace unnecessary comma operator
In reply to Stephen HemmingerUse of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- lib/graph/graph_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/graph/graph_stats.c +1 -1
@@ -254,7 +254,7 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in, *stats_in =NULL ;/* Clear the new struct cluster_node area */ - cluster =RTE_PTR_ADD (stats, stats->sz), + cluster =RTE_PTR_ADD (stats, stats->sz);memset (cluster,0 , stats->cluster_node_size);memcpy (cluster->stat.name, graph_node->node->name,RTE_NODE_NAMESIZE ); cluster->stat.id = graph_node->node->id;
Signature · 1 line
2.47.2
PATCH v3 4/7 test: replace unnecessary comma operators
In reply to Stephen HemmingerUse of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- app/test/test_compressdev.c | 4 ++-- app/test/test_link_bonding_rssconf.c | 2 +- app/test/test_thash.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
app/test/test_compressdev.c +2 -2
@@ -273,7 +273,7 @@ testsuite_setup(void)/* Initializes default values for compress/decompress xforms */ ts_params->def_comp_xform->type =RTE_COMP_COMPRESS ; - ts_params->def_comp_xform->compress.algo =RTE_COMP_ALGO_DEFLATE , + ts_params->def_comp_xform->compress.algo =RTE_COMP_ALGO_DEFLATE ; ts_params->def_comp_xform->compress.deflate.huffman =RTE_COMP_HUFFMAN_DEFAULT ; ts_params->def_comp_xform->compress.level =RTE_COMP_LEVEL_PMD_DEFAULT ;
@@ -281,7 +281,7 @@ testsuite_setup(void) ts_params->def_comp_xform->compress.window_size =DEFAULT_WINDOW_SIZE ; ts_params->def_decomp_xform->type =RTE_COMP_DECOMPRESS ; - ts_params->def_decomp_xform->decompress.algo =RTE_COMP_ALGO_DEFLATE , + ts_params->def_decomp_xform->decompress.algo =RTE_COMP_ALGO_DEFLATE ; ts_params->def_decomp_xform->decompress.chksum =RTE_COMP_CHECKSUM_NONE ; ts_params->def_decomp_xform->decompress.window_size =DEFAULT_WINDOW_SIZE ;
app/test/test_link_bonding_rssconf.c +1 -1
@@ -384,7 +384,7 @@ test_propagate(void) }memset (bond_rss_key, i,sizeof (bond_rss_key)); - bond_rss_conf.rss_hf = default_rss_hf, + bond_rss_conf.rss_hf = default_rss_hf; bond_rss_conf.rss_key = bond_rss_key; bond_rss_conf.rss_key_len =40 ;
app/test/test_thash.c +1 -1
@@ -910,7 +910,7 @@ test_adjust_tuple_mult_reta(void) {uint32_t i, j, np, nt; - nt =0 , np =0 ; + nt =0 ; np =0 ;for (i =0 ; i <CHAR_BIT ; i++) {for (j =6 ; j <=RTE_THASH_RETA_SZ_MAX - i; j++) { np += (test_adjust_tuple_mb (j, i) ==0 );
Signature · 1 line
2.47.2
RE: [PATCH v3 4/7] test: replace unnecessary comma operators
app/test/test_thash.c test_adjust_tuple_mult_reta(void) · line 913
Quoted 10 lines
app/test/test_thash.c +1
-1@@ -910,7 +910,7 @@ test_adjust_tuple_mult_reta(void) {uint32_t i, j, np, nt; - nt =0 , np =0 ; + nt =0 ; np =0 ;
Consider putting these assignments on separate lines.
Quoted 5 lines
app/test/test_thash.c +0
-1for (i =0 ; i <CHAR_BIT ; i++) {for (j =6 ; j <=RTE_THASH_RETA_SZ_MAX - i; j++) { np += (test_adjust_tuple_mb (j, i) ==0 ); --2.47.2
PATCH v3 5/7 app/testpmd: replace comma operator with bracket
In reply to Stephen HemmingerUse while with brackets in favor of comma operator.
In flow print replace with temporary variable.
--- app/test-pmd/cmdline_flow.c | 6 ++++-- app/test-pmd/config.c | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-)
app/test-pmd/cmdline_flow.c +4 -2
@@ -8333,8 +8333,10 @@ parse_prefix(struct context *ctx, const struct token *token,if (!ctx->object)return len; extra -= u; -while (u--) - (v <<=1 , v |=1 ); +while (u--) { + v <<=1 ; + v |=1 ; + } v <<= extra;if (!arg_entry_bf_fill (ctx->object, v, arg) || !arg_entry_bf_fill (ctx->objmask,-1 , arg))
app/test-pmd/config.c +6 -4
@@ -1497,7 +1497,7 @@ port_flow_complain(struct rte_flow_error *error) [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action", };const char *errstr; -char buf[32 ]; +char cause_buf[32 ] ="" ;int err = rte_errno; if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
@@ -1505,10 +1505,12 @@ port_flow_complain(struct rte_flow_error *error) errstr ="unknown type" ; else errstr = errstrlist[error->type]; + +if (error->cause) +snprintf (cause_buf,sizeof (cause_buf),"cause: %p, " , error->cause); +fprintf (stderr,"%s(): Caught PMD error type %d (%s): %s%s: %s\n" , - __func__, error->type, errstr, - error->cause ? (snprintf (buf,sizeof (buf),"cause: %p, " , - error->cause), buf) :"" , + __func__, error->type, errstr, cause_buf, error->message ? error->message :"(no stated reason)" ,rte_strerror (err));
Signature · 1 line
2.47.2
PATCH v3 6/7 examples: remove unnecessary use of comma operator
In reply to Stephen HemmingerUse of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- examples/l2fwd-event/l2fwd_event_generic.c | 2 +- examples/l3fwd/l3fwd_event_generic.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
examples/l2fwd-event/l2fwd_event_generic.c +1 -1
@@ -207,7 +207,7 @@ l2fwd_event_queue_setup_generic(struct l2fwd_resources *rsrc, } event_q_conf.event_queue_cfg |=RTE_EVENT_QUEUE_CFG_SINGLE_LINK ; - event_q_conf.priority =RTE_EVENT_DEV_PRIORITY_HIGHEST , + event_q_conf.priority =RTE_EVENT_DEV_PRIORITY_HIGHEST ; ret =rte_event_queue_setup (event_d_id, event_q_id, &event_q_conf);if (ret <0 )rte_panic ("Error in configuring event queue for Tx adapter\n" );
examples/l3fwd/l3fwd_event_generic.c +1 -1
@@ -190,7 +190,7 @@ l3fwd_event_queue_setup_generic(uint32_t event_queue_cfg) } event_q_conf.event_queue_cfg |=RTE_EVENT_QUEUE_CFG_SINGLE_LINK ; - event_q_conf.priority =RTE_EVENT_DEV_PRIORITY_HIGHEST , + event_q_conf.priority =RTE_EVENT_DEV_PRIORITY_HIGHEST ; ret =rte_event_queue_setup (event_d_id, event_q_id, &event_q_conf);if (ret <0 )rte_panic ("Error in configuring event queue for Tx adapter\n" );
Signature · 1 line
2.47.2
PATCH v3 7/7 config: enable comma warnings
In reply to Stephen HemmingerClang (3.9 or later) has a -Wcomma that emits warnings for questionable uses of the comma operator.
Don't enable it for drivers since many drivers still use comma operator unnecessarily.
--- config/meson.build | 1 + drivers/meson.build | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
config/meson.build +1 -0
@@ -313,6 +313,7 @@ endif global_cflags = [ # additional warnings in alphabetical order '-Wcast-qual', + '-Wcomma', '-Wdeprecated', '-Wformat', '-Wformat-nonliteral',
drivers/meson.build +1 -1
@@ -59,7 +59,7 @@ default_cflags = machine_args default_cflags += ['-DALLOW_EXPERIMENTAL_API'] default_cflags += ['-DALLOW_INTERNAL_API'] -warning_disable_cflags = ['-Wno-format-truncation', '-Wno-address-of-packed-member'] +warning_disable_cflags = ['-Wno-format-truncation', '-Wno-address-of-packed-member', '-Wno-comma'] foreach cflag:warning_disable_cflags if cc.has_argument(cflag) default_cflags += cflag
Signature · 1 line
2.47.2
RE: [PATCH v3 0/7] avoid unnecessary use of comma operator
In reply to Stephen HemmingerQuoted 6 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Friday, 15 August 2025 18.26Clang has ability to detect suspicious use of comma operator where a semicolon would have the same effect.
Easy enough to fix in DPDK code.
Thank you for cleaning up DPDK with this improvement.
v4 cover avoid unnecessary use of commaa operator
In reply to Stephen HemmingerClang has ability to detect suspicious use of comma operator where a semicolon would have the same effect.
Easy enough to fix in DPDK code.
v4 - review feedback about consolidating assignments
fix Broadcom drivers (Intel and Nvidia still have warnings)
Stephen Hemminger (9):
eal: replace unnecessary comma operator
ipsec: replace unnecessary comma operator
graph: replace unnecessary comma operator
test: replace unnecessary comma operators app/testpmd: replace comma operator with bracket
examples: remove unnecessary use of comma operator net/bnx2x: remove unnecessary comma operator net/bnxt: remove unnecessary use of comma operator
config: enable comma warnings
app/test-pmd/cmdline_flow.c | 6 ++++-- app/test-pmd/config.c | 10 ++++++---- app/test/test_compressdev.c | 4 ++-- app/test/test_link_bonding_rssconf.c | 2 +- app/test/test_thash.c | 7 +++---- config/meson.build | 1 + drivers/meson.build | 2 +- drivers/net/bnx2x/bnx2x.c | 4 ++-- drivers/net/bnxt/tf_core/tf_msg.c | 4 ++-- examples/l2fwd-event/l2fwd_event_generic.c | 2 +- examples/l3fwd/l3fwd_event_generic.c | 2 +- lib/eal/common/rte_malloc.c | 4 ++-- lib/eal/linux/eal_alarm.c | 6 ++++-- lib/graph/graph_stats.c | 2 +- lib/ipsec/misc.h | 8 +++----- 15 files changed, 34 insertions(+), 30 deletions(-)
--
2.47.2
PATCH v4 1/9 eal: replace unnecessary comma operator
Use of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- lib/eal/common/rte_malloc.c | 4 ++-- lib/eal/linux/eal_alarm.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-)
lib/eal/common/rte_malloc.c +2 -2
@@ -202,8 +202,8 @@ rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket) } user_size = size; - - size =RTE_CACHE_LINE_ROUNDUP (size), align =RTE_CACHE_LINE_ROUNDUP (align); + size =RTE_CACHE_LINE_ROUNDUP (size); + align =RTE_CACHE_LINE_ROUNDUP (align);/* check requested socket id and alignment matches first, and if ok, * see if we can resize block
lib/eal/linux/eal_alarm.c +4 -2
@@ -125,8 +125,10 @@ eal_alarm_callback(void *arg __rte_unused) atime.it_value.tv_sec = ap->time.tv_sec; atime.it_value.tv_nsec = ap->time.tv_usec *NS_PER_US ;/* perform borrow for subtraction if necessary */ -if (now.tv_nsec > (ap->time.tv_usec *NS_PER_US )) - atime.it_value.tv_sec--, atime.it_value.tv_nsec +=US_PER_S *NS_PER_US ; +if (now.tv_nsec > (ap->time.tv_usec *NS_PER_US )) { + atime.it_value.tv_sec--; + atime.it_value.tv_nsec +=US_PER_S *NS_PER_US ; + } atime.it_value.tv_sec -= now.tv_sec; atime.it_value.tv_nsec -= now.tv_nsec;
Signature · 1 line
2.47.2
PATCH v4 2/9 ipsec: replace unnecessary comma operator
In reply to Stephen HemmingerUse of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- lib/ipsec/misc.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
lib/ipsec/misc.h +3 -5
@@ -19,12 +19,9 @@ static inline void move_bad_mbufs(struct rte_mbuf *mb[], const uint32_t bad_idx[], uint32_t nb_mb, uint32_t nb_bad) { - uint32_t i, j, k; + uint32_t i, j = 0, k = 0;struct rte_mbuf *drb[nb_bad]; - j =0 ; - k =0 ; -/* copy bad ones into a temp place */ for (i =0 ; i != nb_mb; i++) {if (j != nb_bad && i == bad_idx[j])
@@ -126,7 +123,8 @@ cpu_crypto_bulk(const struct rte_ipsec_session *ss,const uint32_t vnum =RTE_DIM (vec); - j =0 , n =0 ; + j =0 ; + n =0 ; vofs =0 ;for (i =0 ; i != num; i++) {
Signature · 1 line
2.47.2
Re: [PATCH v4 2/9] ipsec: replace unnecessary comma operator
Quoted 11 lines · Stephen Hemminger
Use of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
Signed-off-by Stephen Hemminger <[email protected]>Acked-by Chengwen Feng <[email protected]>Acked-by Morten Brørup <[email protected]>--- lib/ipsec/misc.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
Re: [PATCH v4 2/9] ipsec: replace unnecessary comma operator
In reply to Stephen HemmingerQuoted 30 lines · Stephen Hemminger
Use of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
Signed-off-by Stephen Hemminger <[email protected]>Acked-by Chengwen Feng <[email protected]>Acked-by Morten Brørup <[email protected]>--- lib/ipsec/misc.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)lib/ipsec/misc.h +1
-4@@ -19,12 +19,9 @@ static inline void move_bad_mbufs(struct rte_mbuf *mb[], const uint32_t bad_idx[], uint32_t nb_mb, uint32_t nb_bad) { - uint32_t i, j, k; + uint32_t i, j = 0, k = 0;struct rte_mbuf *drb[nb_bad]; - j =0 ; - k =0 ; -/* copy bad ones into a temp place */ for (i =0 ; i != nb_mb; i++) {if (j != nb_bad && i == bad_idx[j])
lib/ipsec/misc.h cpu_crypto_bulk(const struct rte_ipsec_session *ss, · line 127
Quoted 6 lines
lib/ipsec/misc.h +2
-1@@ -126,7 +123,8 @@ cpu_crypto_bulk(const struct rte_ipsec_session *ss,const uint32_t vnum =RTE_DIM (vec); - j =0 , n =0 ; + j =0 ; + n =0 ;
Nit: These can also be assigned at definition time.
Quoted 6 lines
lib/ipsec/misc.h +0
-0vofs =0 ;for (i =0 ; i != num; i++) {Signature · 1 line
2.47.2
PATCH v4 3/9 graph: replace unnecessary comma operator
In reply to Stephen HemmingerUse of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- lib/graph/graph_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/graph/graph_stats.c +1 -1
@@ -254,7 +254,7 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in, *stats_in =NULL ;/* Clear the new struct cluster_node area */ - cluster =RTE_PTR_ADD (stats, stats->sz), + cluster =RTE_PTR_ADD (stats, stats->sz);memset (cluster,0 , stats->cluster_node_size);memcpy (cluster->stat.name, graph_node->node->name,RTE_NODE_NAMESIZE ); cluster->stat.id = graph_node->node->id;
Signature · 1 line
2.47.2
PATCH v4 4/9 test: replace unnecessary comma operators
In reply to Stephen HemmingerUse of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- app/test/test_compressdev.c | 4 ++-- app/test/test_link_bonding_rssconf.c | 2 +- app/test/test_thash.c | 7 +++---- 3 files changed, 6 insertions(+), 7 deletions(-)
app/test/test_compressdev.c +2 -2
@@ -273,7 +273,7 @@ testsuite_setup(void)/* Initializes default values for compress/decompress xforms */ ts_params->def_comp_xform->type =RTE_COMP_COMPRESS ; - ts_params->def_comp_xform->compress.algo =RTE_COMP_ALGO_DEFLATE , + ts_params->def_comp_xform->compress.algo =RTE_COMP_ALGO_DEFLATE ; ts_params->def_comp_xform->compress.deflate.huffman =RTE_COMP_HUFFMAN_DEFAULT ; ts_params->def_comp_xform->compress.level =RTE_COMP_LEVEL_PMD_DEFAULT ;
@@ -281,7 +281,7 @@ testsuite_setup(void) ts_params->def_comp_xform->compress.window_size =DEFAULT_WINDOW_SIZE ; ts_params->def_decomp_xform->type =RTE_COMP_DECOMPRESS ; - ts_params->def_decomp_xform->decompress.algo =RTE_COMP_ALGO_DEFLATE , + ts_params->def_decomp_xform->decompress.algo =RTE_COMP_ALGO_DEFLATE ; ts_params->def_decomp_xform->decompress.chksum =RTE_COMP_CHECKSUM_NONE ; ts_params->def_decomp_xform->decompress.window_size =DEFAULT_WINDOW_SIZE ;
app/test/test_link_bonding_rssconf.c +1 -1
@@ -384,7 +384,7 @@ test_propagate(void) }memset (bond_rss_key, i,sizeof (bond_rss_key)); - bond_rss_conf.rss_hf = default_rss_hf, + bond_rss_conf.rss_hf = default_rss_hf; bond_rss_conf.rss_key = bond_rss_key; bond_rss_conf.rss_key_len =40 ;
app/test/test_thash.c +3 -4
@@ -908,11 +908,10 @@ test_adjust_tuple_mb(uint32_t reta_sz, uint32_t bofs)static int test_adjust_tuple_mult_reta (void ) { -uint32_t i, j, np, nt; +uint32_t np =0 , nt =0 ; - nt =0 , np =0 ; -for (i =0 ; i <CHAR_BIT ; i++) { -for (j =6 ; j <=RTE_THASH_RETA_SZ_MAX - i; j++) { +for (uint32_t i =0 ; i <CHAR_BIT ; i++) { +for (uint32_t j =6 ; j <=RTE_THASH_RETA_SZ_MAX - i; j++) { np += (test_adjust_tuple_mb (j, i) ==0 ); nt++; }
Signature · 1 line
2.47.2
PATCH v4 5/9 app/testpmd: replace comma operator with bracket
In reply to Stephen HemmingerUse while with brackets in favor of comma operator.
In flow print replace with temporary variable.
--- app/test-pmd/cmdline_flow.c | 6 ++++-- app/test-pmd/config.c | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-)
app/test-pmd/cmdline_flow.c +4 -2
@@ -8333,8 +8333,10 @@ parse_prefix(struct context *ctx, const struct token *token,if (!ctx->object)return len; extra -= u; -while (u--) - (v <<=1 , v |=1 ); +while (u--) { + v <<=1 ; + v |=1 ; + } v <<= extra;if (!arg_entry_bf_fill (ctx->object, v, arg) || !arg_entry_bf_fill (ctx->objmask,-1 , arg))
app/test-pmd/config.c +6 -4
@@ -1497,7 +1497,7 @@ port_flow_complain(struct rte_flow_error *error) [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action", };const char *errstr; -char buf[32 ]; +char cause_buf[32 ] ="" ;int err = rte_errno; if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
@@ -1505,10 +1505,12 @@ port_flow_complain(struct rte_flow_error *error) errstr ="unknown type" ; else errstr = errstrlist[error->type]; + +if (error->cause) +snprintf (cause_buf,sizeof (cause_buf),"cause: %p, " , error->cause); +fprintf (stderr,"%s(): Caught PMD error type %d (%s): %s%s: %s\n" , - __func__, error->type, errstr, - error->cause ? (snprintf (buf,sizeof (buf),"cause: %p, " , - error->cause), buf) :"" , + __func__, error->type, errstr, cause_buf, error->message ? error->message :"(no stated reason)" ,rte_strerror (err));
Signature · 1 line
2.47.2
PATCH v4 6/9 examples: remove unnecessary use of comma operator
In reply to Stephen HemmingerUse of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- examples/l2fwd-event/l2fwd_event_generic.c | 2 +- examples/l3fwd/l3fwd_event_generic.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
examples/l2fwd-event/l2fwd_event_generic.c +1 -1
@@ -207,7 +207,7 @@ l2fwd_event_queue_setup_generic(struct l2fwd_resources *rsrc, } event_q_conf.event_queue_cfg |=RTE_EVENT_QUEUE_CFG_SINGLE_LINK ; - event_q_conf.priority =RTE_EVENT_DEV_PRIORITY_HIGHEST , + event_q_conf.priority =RTE_EVENT_DEV_PRIORITY_HIGHEST ; ret =rte_event_queue_setup (event_d_id, event_q_id, &event_q_conf);if (ret <0 )rte_panic ("Error in configuring event queue for Tx adapter\n" );
examples/l3fwd/l3fwd_event_generic.c +1 -1
@@ -190,7 +190,7 @@ l3fwd_event_queue_setup_generic(uint32_t event_queue_cfg) } event_q_conf.event_queue_cfg |=RTE_EVENT_QUEUE_CFG_SINGLE_LINK ; - event_q_conf.priority =RTE_EVENT_DEV_PRIORITY_HIGHEST , + event_q_conf.priority =RTE_EVENT_DEV_PRIORITY_HIGHEST ; ret =rte_event_queue_setup (event_d_id, event_q_id, &event_q_conf);if (ret <0 )rte_panic ("Error in configuring event queue for Tx adapter\n" );
Signature · 1 line
2.47.2
PATCH v4 7/9 net/bnx2x: remove unnecessary comma operator
In reply to Stephen HemmingerUse semicolon to break lines.
--- drivers/net/bnx2x/bnx2x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/bnx2x/bnx2x.c +2 -2
@@ -1537,8 +1537,8 @@ bnx2x_set_q_rx_mode(struct bnx2x_softc *sc, uint8_t cl_id, ramrod_param.rdata =BNX2X_SP (sc, rx_mode_rdata); ramrod_param.rdata_mapping = - (rte_iova_t )BNX2X_SP_MAPPING (sc, rx_mode_rdata), -rte_bit_relaxed_set32 (ECORE_FILTER_RX_MODE_PENDING , &sc->sp_state); + (rte_iova_t )BNX2X_SP_MAPPING (sc, rx_mode_rdata); +rte_bit_relaxed_set32 (ECORE_FILTER_RX_MODE_PENDING , &sc->sp_state); ramrod_param.ramrod_flags = ramrod_flags; ramrod_param.rx_mode_flags = rx_mode_flags;
Signature · 1 line
2.47.2
PATCH v4 8/9 net/bnxt: remove unnecessary use of comma operator
In reply to Stephen HemmingerShould use semicolon here.
--- drivers/net/bnxt/tf_core/tf_msg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/bnxt/tf_core/tf_msg.c +2 -2
@@ -385,7 +385,7 @@ tf_msg_session_qcfg(struct tf *tfp)/* Populate the request */ req.fw_session_id =tfp_cpu_to_le_32 (fw_session_id); - parms.tf_type =HWRM_TF_SESSION_QCFG , + parms.tf_type =HWRM_TF_SESSION_QCFG ; parms.req_data = (uint32_t *)&req; parms.req_size =sizeof (req); parms.resp_data = (uint32_t *)&resp;
@@ -1862,7 +1862,7 @@ tf_msg_get_version(struct bnxt *bp,struct tfp_send_msg_parms parms = {0 };/* Populate the request */ - parms.tf_type =HWRM_TF_VERSION_GET , + parms.tf_type =HWRM_TF_VERSION_GET ; parms.req_data = (uint32_t *)&req; parms.req_size =sizeof (req); parms.resp_data = (uint32_t *)&resp;
Signature · 1 line
2.47.2
PATCH v4 9/9 config: enable comma warnings
In reply to Stephen HemmingerClang (3.9 or later) has a -Wcomma that emits warnings for questionable uses of the comma operator.
Don't enable it for drivers since many drivers still use comma operator unnecessarily.
--- config/meson.build | 1 + drivers/meson.build | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
config/meson.build +1 -0
@@ -313,6 +313,7 @@ endif global_cflags = [ # additional warnings in alphabetical order '-Wcast-qual', + '-Wcomma', '-Wdeprecated', '-Wformat', '-Wformat-nonliteral',
drivers/meson.build +1 -1
@@ -59,7 +59,7 @@ default_cflags = machine_args default_cflags += ['-DALLOW_EXPERIMENTAL_API'] default_cflags += ['-DALLOW_INTERNAL_API'] -warning_disable_cflags = ['-Wno-format-truncation', '-Wno-address-of-packed-member'] +warning_disable_cflags = ['-Wno-format-truncation', '-Wno-address-of-packed-member', '-Wno-comma'] foreach cflag:warning_disable_cflags if cc.has_argument(cflag) default_cflags += cflag
Signature · 1 line
2.47.2
Re: [PATCH v4 9/9] config: enable comma warnings
Quoted 32 lines · Stephen Hemminger
Clang (3.9 or later) has a -Wcomma that emits warnings for questionable uses of the comma operator.
Don't enable it for drivers since many drivers still use comma operator unnecessarily.
Signed-off-by Stephen Hemminger <[email protected]>Acked-by Chengwen Feng <[email protected]>Acked-by Morten Brørup <[email protected]>--- config/meson.build | 1 + drivers/meson.build | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)config/meson.build +1
-0@@ -313,6 +313,7 @@ endif global_cflags = [ # additional warnings in alphabetical order '-Wcast-qual', + '-Wcomma', '-Wdeprecated', '-Wformat', '-Wformat-nonliteral',drivers/meson.build +0
-0
drivers/meson.build default_cflags = machine_args · line 62
Quoted 5 lines
drivers/meson.build +1
-1@@ -59,7 +59,7 @@ default_cflags = machine_args default_cflags += ['-DALLOW_EXPERIMENTAL_API'] default_cflags += ['-DALLOW_INTERNAL_API'] -warning_disable_cflags = ['-Wno-format-truncation', '-Wno-address-of-packed-member'] +warning_disable_cflags = ['-Wno-format-truncation', '-Wno-address-of-packed-member', '-Wno-comma']
Since this patchset has already fixed some drivers, are we at a point where we can just disable this warning on a driver-by-driver basis rather than globally? That makes it easier to spot where the issues are and easier allows incremental improvement.
Quoted 6 lines
drivers/meson.build +0
-0foreach cflag:warning_disable_cflags if cc.has_argument(cflag) default_cflags += cflagSignature · 1 line
2.47.2
Re: [PATCH v4 9/9] config: enable comma warnings
Quoted 8 lines · On Mon, 18 Aug 2025 17:36:21 +0100 Bruce Richardson…
Quoted 8 lines
drivers/meson.build +0
-0@@ -59,7 +59,7 @@ default_cflags = machine_args default_cflags += ['-DALLOW_EXPERIMENTAL_API'] default_cflags += ['-DALLOW_INTERNAL_API']
Quoted 7 lines
drivers/meson.build default_cflags = machine_args · line 62
Quoted 2 lines
drivers/meson.build +1
-1-warning_disable_cflags = ['-Wno-format-truncation', '-Wno-address-of-packed-member'] +warning_disable_cflags = ['-Wno-format-truncation', '-Wno-address-of-packed-member', '-Wno-comma']Since this patchset has already fixed some drivers, are we at a point where we can just disable this warning on a driver-by-driver basis rather than globally? That makes it easier to spot where the issues are and easier allows incremental improvement.
Would like to get all drivers fixed in final version.
The issue is that several drivers are open coding FOREACH_SAFE macros and there is other series to address that.
v5 cover avoid unnecessary use of comma operator
In reply to Stephen HemmingerClang has ability to detect suspicious use of comma operator where a semicolon would have the same effect.
Easy enough to fix in DPDK code.
v5 - rebase to current main
Stephen Hemminger (8):
eal: replace unnecessary comma operator
ipsec: replace unnecessary comma operator
test: replace unnecessary comma operators app/testpmd: replace comma operator with bracket
examples: remove unnecessary use of comma operator net/bnx2x: remove unnecessary comma operator net/bnxt: remove unnecessary use of comma operator
config: enable comma warnings
app/test-pmd/cmdline_flow.c | 6 ++++-- app/test-pmd/config.c | 10 ++++++---- app/test/test_compressdev.c | 4 ++-- app/test/test_link_bonding_rssconf.c | 2 +- app/test/test_thash.c | 7 +++---- config/meson.build | 1 + drivers/meson.build | 2 +- drivers/net/bnx2x/bnx2x.c | 4 ++-- drivers/net/bnxt/tf_core/tf_msg.c | 4 ++-- examples/l2fwd-event/l2fwd_event_generic.c | 2 +- examples/l3fwd/l3fwd_event_generic.c | 2 +- lib/eal/common/rte_malloc.c | 4 ++-- lib/eal/linux/eal_alarm.c | 6 ++++-- lib/ipsec/misc.h | 8 +++----- 14 files changed, 33 insertions(+), 29 deletions(-)
Signature · 1 line
2.47.3
PATCH v5 1/8 eal: replace unnecessary comma operator
Use of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- lib/eal/common/rte_malloc.c | 4 ++-- lib/eal/linux/eal_alarm.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-)
lib/eal/common/rte_malloc.c +2 -2
@@ -202,8 +202,8 @@ rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket) } user_size = size; - - size =RTE_CACHE_LINE_ROUNDUP (size), align =RTE_CACHE_LINE_ROUNDUP (align); + size =RTE_CACHE_LINE_ROUNDUP (size); + align =RTE_CACHE_LINE_ROUNDUP (align);/* check requested socket id and alignment matches first, and if ok, * see if we can resize block
lib/eal/linux/eal_alarm.c +4 -2
@@ -125,8 +125,10 @@ eal_alarm_callback(void *arg __rte_unused) atime.it_value.tv_sec = ap->time.tv_sec; atime.it_value.tv_nsec = ap->time.tv_usec *NS_PER_US ;/* perform borrow for subtraction if necessary */ -if (now.tv_nsec > (ap->time.tv_usec *NS_PER_US )) - atime.it_value.tv_sec--, atime.it_value.tv_nsec +=US_PER_S *NS_PER_US ; +if (now.tv_nsec > (ap->time.tv_usec *NS_PER_US )) { + atime.it_value.tv_sec--; + atime.it_value.tv_nsec +=US_PER_S *NS_PER_US ; + } atime.it_value.tv_sec -= now.tv_sec; atime.it_value.tv_nsec -= now.tv_nsec;
Signature · 1 line
2.47.3
PATCH v5 2/8 ipsec: replace unnecessary comma operator
In reply to Stephen HemmingerUse of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- lib/ipsec/misc.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
lib/ipsec/misc.h +3 -5
@@ -19,12 +19,9 @@ static inline void move_bad_mbufs(struct rte_mbuf *mb[], const uint32_t bad_idx[], uint32_t nb_mb, uint32_t nb_bad) { - uint32_t i, j, k; + uint32_t i, j = 0, k = 0;struct rte_mbuf *drb[nb_bad]; - j =0 ; - k =0 ; -/* copy bad ones into a temp place */ for (i =0 ; i != nb_mb; i++) {if (j != nb_bad && i == bad_idx[j])
@@ -126,7 +123,8 @@ cpu_crypto_bulk(const struct rte_ipsec_session *ss,const uint32_t vnum =RTE_DIM (vec); - j =0 , n =0 ; + j =0 ; + n =0 ; vofs =0 ;for (i =0 ; i != num; i++) {
Signature · 1 line
2.47.3
PATCH v5 3/8 test: replace unnecessary comma operators
In reply to Stephen HemmingerUse of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- app/test/test_compressdev.c | 4 ++-- app/test/test_link_bonding_rssconf.c | 2 +- app/test/test_thash.c | 7 +++---- 3 files changed, 6 insertions(+), 7 deletions(-)
app/test/test_compressdev.c +2 -2
@@ -273,7 +273,7 @@ testsuite_setup(void)/* Initializes default values for compress/decompress xforms */ ts_params->def_comp_xform->type =RTE_COMP_COMPRESS ; - ts_params->def_comp_xform->compress.algo =RTE_COMP_ALGO_DEFLATE , + ts_params->def_comp_xform->compress.algo =RTE_COMP_ALGO_DEFLATE ; ts_params->def_comp_xform->compress.deflate.huffman =RTE_COMP_HUFFMAN_DEFAULT ; ts_params->def_comp_xform->compress.level =RTE_COMP_LEVEL_PMD_DEFAULT ;
@@ -281,7 +281,7 @@ testsuite_setup(void) ts_params->def_comp_xform->compress.window_size =DEFAULT_WINDOW_SIZE ; ts_params->def_decomp_xform->type =RTE_COMP_DECOMPRESS ; - ts_params->def_decomp_xform->decompress.algo =RTE_COMP_ALGO_DEFLATE , + ts_params->def_decomp_xform->decompress.algo =RTE_COMP_ALGO_DEFLATE ; ts_params->def_decomp_xform->decompress.chksum =RTE_COMP_CHECKSUM_NONE ; ts_params->def_decomp_xform->decompress.window_size =DEFAULT_WINDOW_SIZE ;
app/test/test_link_bonding_rssconf.c +1 -1
@@ -384,7 +384,7 @@ test_propagate(void) }memset (bond_rss_key, i,sizeof (bond_rss_key)); - bond_rss_conf.rss_hf = default_rss_hf, + bond_rss_conf.rss_hf = default_rss_hf; bond_rss_conf.rss_key = bond_rss_key; bond_rss_conf.rss_key_len =40 ;
app/test/test_thash.c +3 -4
@@ -908,11 +908,10 @@ test_adjust_tuple_mb(uint32_t reta_sz, uint32_t bofs)static int test_adjust_tuple_mult_reta (void ) { -uint32_t i, j, np, nt; +uint32_t np =0 , nt =0 ; - nt =0 , np =0 ; -for (i =0 ; i <CHAR_BIT ; i++) { -for (j =6 ; j <=RTE_THASH_RETA_SZ_MAX - i; j++) { +for (uint32_t i =0 ; i <CHAR_BIT ; i++) { +for (uint32_t j =6 ; j <=RTE_THASH_RETA_SZ_MAX - i; j++) { np += (test_adjust_tuple_mb (j, i) ==0 ); nt++; }
Signature · 1 line
2.47.3
PATCH v5 4/8 app/testpmd: replace comma operator with bracket
In reply to Stephen HemmingerUse while with brackets in favor of comma operator.
In flow print replace with temporary variable.
--- app/test-pmd/cmdline_flow.c | 6 ++++-- app/test-pmd/config.c | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-)
app/test-pmd/cmdline_flow.c +4 -2
@@ -8333,8 +8333,10 @@ parse_prefix(struct context *ctx, const struct token *token,if (!ctx->object)return len; extra -= u; -while (u--) - (v <<=1 , v |=1 ); +while (u--) { + v <<=1 ; + v |=1 ; + } v <<= extra;if (!arg_entry_bf_fill (ctx->object, v, arg) || !arg_entry_bf_fill (ctx->objmask,-1 , arg))
app/test-pmd/config.c +6 -4
@@ -1501,7 +1501,7 @@ port_flow_complain(struct rte_flow_error *error) [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action", };const char *errstr; -char buf[32 ]; +char cause_buf[32 ] ="" ;int err = rte_errno; if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
@@ -1509,10 +1509,12 @@ port_flow_complain(struct rte_flow_error *error) errstr ="unknown type" ; else errstr = errstrlist[error->type]; + +if (error->cause) +snprintf (cause_buf,sizeof (cause_buf),"cause: %p, " , error->cause); +fprintf (stderr,"%s(): Caught PMD error type %d (%s): %s%s: %s\n" , - __func__, error->type, errstr, - error->cause ? (snprintf (buf,sizeof (buf),"cause: %p, " , - error->cause), buf) :"" , + __func__, error->type, errstr, cause_buf, error->message ? error->message :"(no stated reason)" ,rte_strerror (err));
Signature · 1 line
2.47.3
PATCH v5 5/8 examples: remove unnecessary use of comma operator
In reply to Stephen HemmingerUse of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
--- examples/l2fwd-event/l2fwd_event_generic.c | 2 +- examples/l3fwd/l3fwd_event_generic.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
examples/l2fwd-event/l2fwd_event_generic.c +1 -1
@@ -207,7 +207,7 @@ l2fwd_event_queue_setup_generic(struct l2fwd_resources *rsrc, } event_q_conf.event_queue_cfg |=RTE_EVENT_QUEUE_CFG_SINGLE_LINK ; - event_q_conf.priority =RTE_EVENT_DEV_PRIORITY_HIGHEST , + event_q_conf.priority =RTE_EVENT_DEV_PRIORITY_HIGHEST ; ret =rte_event_queue_setup (event_d_id, event_q_id, &event_q_conf);if (ret <0 )rte_panic ("Error in configuring event queue for Tx adapter\n" );
examples/l3fwd/l3fwd_event_generic.c +1 -1
@@ -190,7 +190,7 @@ l3fwd_event_queue_setup_generic(uint32_t event_queue_cfg) } event_q_conf.event_queue_cfg |=RTE_EVENT_QUEUE_CFG_SINGLE_LINK ; - event_q_conf.priority =RTE_EVENT_DEV_PRIORITY_HIGHEST , + event_q_conf.priority =RTE_EVENT_DEV_PRIORITY_HIGHEST ; ret =rte_event_queue_setup (event_d_id, event_q_id, &event_q_conf);if (ret <0 )rte_panic ("Error in configuring event queue for Tx adapter\n" );
Signature · 1 line
2.47.3
Re: [PATCH v5 5/8] examples: remove unnecessary use of comma operator
Quoted 4 lines · Stephen Hemminger
Use of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
Signed-off-by Stephen Hemminger <[email protected]>
Re: [PATCH v5 5/8] examples: remove unnecessary use of comma operator
In reply to Stephen HemmingerQuoted 4 lines · Stephen Hemminger
Use of comma as statement separator is discouraged and reported as warning by clang with -Wcomma
Signed-off-by Stephen Hemminger <[email protected]>
PATCH v5 6/8 net/bnx2x: remove unnecessary comma operator
In reply to Stephen HemmingerUse semicolon to break lines.
--- drivers/net/bnx2x/bnx2x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/bnx2x/bnx2x.c +2 -2
@@ -1537,8 +1537,8 @@ bnx2x_set_q_rx_mode(struct bnx2x_softc *sc, uint8_t cl_id, ramrod_param.rdata =BNX2X_SP (sc, rx_mode_rdata); ramrod_param.rdata_mapping = - (rte_iova_t )BNX2X_SP_MAPPING (sc, rx_mode_rdata), -rte_bit_relaxed_set32 (ECORE_FILTER_RX_MODE_PENDING , &sc->sp_state); + (rte_iova_t )BNX2X_SP_MAPPING (sc, rx_mode_rdata); +rte_bit_relaxed_set32 (ECORE_FILTER_RX_MODE_PENDING , &sc->sp_state); ramrod_param.ramrod_flags = ramrod_flags; ramrod_param.rx_mode_flags = rx_mode_flags;
Signature · 1 line
2.47.3
PATCH v5 7/8 net/bnxt: remove unnecessary use of comma operator
In reply to Stephen HemmingerShould use semicolon here.
--- drivers/net/bnxt/tf_core/tf_msg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/bnxt/tf_core/tf_msg.c +2 -2
@@ -385,7 +385,7 @@ tf_msg_session_qcfg(struct tf *tfp)/* Populate the request */ req.fw_session_id =tfp_cpu_to_le_32 (fw_session_id); - parms.tf_type =HWRM_TF_SESSION_QCFG , + parms.tf_type =HWRM_TF_SESSION_QCFG ; parms.req_data = (uint32_t *)&req; parms.req_size =sizeof (req); parms.resp_data = (uint32_t *)&resp;
@@ -1862,7 +1862,7 @@ tf_msg_get_version(struct bnxt *bp,struct tfp_send_msg_parms parms = {0 };/* Populate the request */ - parms.tf_type =HWRM_TF_VERSION_GET , + parms.tf_type =HWRM_TF_VERSION_GET ; parms.req_data = (uint32_t *)&req; parms.req_size =sizeof (req); parms.resp_data = (uint32_t *)&resp;
Signature · 1 line
2.47.3
PATCH v5 8/8 config: enable comma warnings
In reply to Stephen HemmingerClang (3.9 or later) has a -Wcomma that emits warnings for questionable uses of the comma operator.
Don't enable it for drivers since many drivers still use comma operator unnecessarily.
--- config/meson.build | 1 + drivers/meson.build | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
config/meson.build +1 -0
@@ -319,6 +319,7 @@ endif global_cflags = [ # additional warnings in alphabetical order '-Wcast-qual', + '-Wcomma', '-Wdeprecated', '-Wformat', '-Wformat-nonliteral',
drivers/meson.build +1 -1
@@ -86,7 +86,7 @@ default_cflags = machine_args default_cflags += ['-DALLOW_EXPERIMENTAL_API'] default_cflags += ['-DALLOW_INTERNAL_API'] -warning_disable_cflags = ['-Wno-format-truncation', '-Wno-address-of-packed-member'] +warning_disable_cflags = ['-Wno-format-truncation', '-Wno-address-of-packed-member', '-Wno-comma'] foreach cflag:warning_disable_cflags if cc.has_argument(cflag) default_cflags += cflag
Signature · 1 line
2.47.3
Re: [PATCH v5 8/8] config: enable comma warnings
Quoted 11 lines · Stephen Hemminger
Clang (3.9 or later) has a -Wcomma that emits warnings for questionable uses of the comma operator.
Don't enable it for drivers since many drivers still use comma operator unnecessarily.
Signed-off-by Stephen Hemminger <[email protected]>Acked-by Chengwen Feng <[email protected]>Acked-by Morten Brørup <[email protected]>---
Thomas Monjalon
AppliedRe: [PATCH v5 0/8] avoid unnecessary use of comma operator
In reply to Stephen Hemminger17/10/2025 17:02, Stephen Hemminger:
Quoted 4 lines
Clang has ability to detect suspicious use of comma operator where a semicolon would have the same effect.
Easy enough to fix in DPDK code.
Quoted 9 lines
Stephen Hemminger (8):
eal: replace unnecessary comma operator
ipsec: replace unnecessary comma operator
test: replace unnecessary comma operators app/testpmd: replace comma operator with bracket
examples: remove unnecessary use of comma operator net/bnx2x: remove unnecessary comma operator net/bnxt: remove unnecessary use of comma operator
config: enable comma warnings
Applied, thanks.
Please could you open bugs for drivers having such commas?
Re: [PATCH v5 0/8] avoid unnecessary use of comma operator
Quoted 15 lines · On Thu, 23 Oct 2025 22:05:46 +0200 Thomas Monjalon <[email protected]> wrote:
17/10/2025 17:02, Stephen Hemminger:
Quoted 4 lines
Clang has ability to detect suspicious use of comma operator where a semicolon would have the same effect.
Easy enough to fix in DPDK code.Quoted 9 lines
Stephen Hemminger (8):
eal: replace unnecessary comma operator
ipsec: replace unnecessary comma operator
test: replace unnecessary comma operators app/testpmd: replace comma operator with bracket
examples: remove unnecessary use of comma operator net/bnx2x: remove unnecessary comma operator net/bnxt: remove unnecessary use of comma operator
config: enable comma warnings
Quoted 6 lines
Applied, thanks.
Please could you open bugs for drivers having such commas?
Ok done. The bugs are grouped into Intel, Mlx, and bnxt.
Re: [PATCH v5 0/8] avoid unnecessary use of comma operator
24/10/2025 01:49, Stephen Hemminger:
Quoted 18 lines
Quoted 15 lines · On Thu, 23 Oct 2025 22:05:46 +0200 Thomas Monjalon <[email protected]> wrote:
17/10/2025 17:02, Stephen Hemminger:
Quoted 13 lines
Clang has ability to detect suspicious use of comma operator where a semicolon would have the same effect.
Easy enough to fix in DPDK code.Stephen Hemminger (8):
eal: replace unnecessary comma operator
ipsec: replace unnecessary comma operator
test: replace unnecessary comma operators app/testpmd: replace comma operator with bracket
examples: remove unnecessary use of comma operator net/bnx2x: remove unnecessary comma operator net/bnxt: remove unnecessary use of comma operator
config: enable comma warnings
Quoted 5 lines
Quoted 3 lines
Applied, thanks.
Please could you open bugs for drivers having such commas?
Ok done. The bugs are grouped into Intel, Mlx, and bnxt.
Thank you.