All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2-next] ip: Convert non-constant initializers to macros
@ 2022-05-31 11:35 Petr Machata
  2022-05-31 14:12 ` Ido Schimmel
  0 siblings, 1 reply; 2+ messages in thread
From: Petr Machata @ 2022-05-31 11:35 UTC (permalink / raw)
  To: netdev
  Cc: David Ahern, Ido Schimmel, Tariq Toukan, Petr Machata, Stephen Hemminger

As per the C standard, "expressions in an initializer for an object that
has static or thread storage duration shall be constant expressions".
Aggregate objects are not constant expressions. Newer GCC doesn't mind, but
older GCC and LLVM do.

Therefore convert to a macro. And since all these macros will look very
similar, extract a generic helper, IPSTATS_STAT_DESC_XSTATS_LEAF, which
takes the leaf name as an argument and initializes the rest as appropriate
for an xstats descriptor.

Reported-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Petr Machata <petrm@nvidia.com>
---
 ip/ip_common.h     |  7 +++++++
 ip/iplink_bond.c   | 11 ++---------
 ip/iplink_bridge.c | 22 ++++------------------
 3 files changed, 13 insertions(+), 27 deletions(-)

diff --git a/ip/ip_common.h b/ip/ip_common.h
index ffa633e0..c4cb1bcb 100644
--- a/ip/ip_common.h
+++ b/ip/ip_common.h
@@ -205,6 +205,13 @@ void ipstats_stat_desc_pack_xstats(struct ipstats_stat_dump_filters *filters,
 int ipstats_stat_desc_show_xstats(struct ipstats_stat_show_attrs *attrs,
 				  const struct ipstats_stat_desc *desc);
 
+#define IPSTATS_STAT_DESC_XSTATS_LEAF(NAME) {		\
+		.name = (NAME),				\
+		.kind = IPSTATS_STAT_DESC_KIND_LEAF,	\
+		.show = &ipstats_stat_desc_show_xstats,	\
+		.pack = &ipstats_stat_desc_pack_xstats,	\
+	}
+
 #ifndef	INFINITY_LIFE_TIME
 #define     INFINITY_LIFE_TIME      0xFFFFFFFFU
 #endif
diff --git a/ip/iplink_bond.c b/ip/iplink_bond.c
index 15db19a3..7943499e 100644
--- a/ip/iplink_bond.c
+++ b/ip/iplink_bond.c
@@ -923,16 +923,9 @@ struct link_util bond_link_util = {
 	.print_ifla_xstats = bond_print_xstats,
 };
 
-static const struct ipstats_stat_desc ipstats_stat_desc_bond_tmpl_lacp = {
-	.name = "802.3ad",
-	.kind = IPSTATS_STAT_DESC_KIND_LEAF,
-	.show = &ipstats_stat_desc_show_xstats,
-	.pack = &ipstats_stat_desc_pack_xstats,
-};
-
 static const struct ipstats_stat_desc_xstats
 ipstats_stat_desc_xstats_bond_lacp = {
-	.desc = ipstats_stat_desc_bond_tmpl_lacp,
+	.desc = IPSTATS_STAT_DESC_XSTATS_LEAF("802.3ad"),
 	.xstats_at = IFLA_STATS_LINK_XSTATS,
 	.link_type_at = LINK_XSTATS_TYPE_BOND,
 	.inner_max = BOND_XSTATS_MAX,
@@ -954,7 +947,7 @@ const struct ipstats_stat_desc ipstats_stat_desc_xstats_bond_group = {
 
 static const struct ipstats_stat_desc_xstats
 ipstats_stat_desc_xstats_slave_bond_lacp = {
-	.desc = ipstats_stat_desc_bond_tmpl_lacp,
+	.desc = IPSTATS_STAT_DESC_XSTATS_LEAF("802.3ad"),
 	.xstats_at = IFLA_STATS_LINK_XSTATS_SLAVE,
 	.link_type_at = LINK_XSTATS_TYPE_BOND,
 	.inner_max = BOND_XSTATS_MAX,
diff --git a/ip/iplink_bridge.c b/ip/iplink_bridge.c
index 3feb6109..0f950d37 100644
--- a/ip/iplink_bridge.c
+++ b/ip/iplink_bridge.c
@@ -937,23 +937,9 @@ struct link_util bridge_link_util = {
 	.print_ifla_xstats = bridge_print_xstats,
 };
 
-static const struct ipstats_stat_desc ipstats_stat_desc_bridge_tmpl_stp = {
-	.name = "stp",
-	.kind = IPSTATS_STAT_DESC_KIND_LEAF,
-	.show = &ipstats_stat_desc_show_xstats,
-	.pack = &ipstats_stat_desc_pack_xstats,
-};
-
-static const struct ipstats_stat_desc ipstats_stat_desc_bridge_tmpl_mcast = {
-	.name = "mcast",
-	.kind = IPSTATS_STAT_DESC_KIND_LEAF,
-	.show = &ipstats_stat_desc_show_xstats,
-	.pack = &ipstats_stat_desc_pack_xstats,
-};
-
 static const struct ipstats_stat_desc_xstats
 ipstats_stat_desc_xstats_bridge_stp = {
-	.desc = ipstats_stat_desc_bridge_tmpl_stp,
+	.desc = IPSTATS_STAT_DESC_XSTATS_LEAF("stp"),
 	.xstats_at = IFLA_STATS_LINK_XSTATS,
 	.link_type_at = LINK_XSTATS_TYPE_BRIDGE,
 	.inner_max = BRIDGE_XSTATS_MAX,
@@ -963,7 +949,7 @@ ipstats_stat_desc_xstats_bridge_stp = {
 
 static const struct ipstats_stat_desc_xstats
 ipstats_stat_desc_xstats_bridge_mcast = {
-	.desc = ipstats_stat_desc_bridge_tmpl_mcast,
+	.desc = IPSTATS_STAT_DESC_XSTATS_LEAF("mcast"),
 	.xstats_at = IFLA_STATS_LINK_XSTATS,
 	.link_type_at = LINK_XSTATS_TYPE_BRIDGE,
 	.inner_max = BRIDGE_XSTATS_MAX,
@@ -986,7 +972,7 @@ const struct ipstats_stat_desc ipstats_stat_desc_xstats_bridge_group = {
 
 static const struct ipstats_stat_desc_xstats
 ipstats_stat_desc_xstats_slave_bridge_stp = {
-	.desc = ipstats_stat_desc_bridge_tmpl_stp,
+	.desc = IPSTATS_STAT_DESC_XSTATS_LEAF("stp"),
 	.xstats_at = IFLA_STATS_LINK_XSTATS_SLAVE,
 	.link_type_at = LINK_XSTATS_TYPE_BRIDGE,
 	.inner_max = BRIDGE_XSTATS_MAX,
@@ -996,7 +982,7 @@ ipstats_stat_desc_xstats_slave_bridge_stp = {
 
 static const struct ipstats_stat_desc_xstats
 ipstats_stat_desc_xstats_slave_bridge_mcast = {
-	.desc = ipstats_stat_desc_bridge_tmpl_mcast,
+	.desc = IPSTATS_STAT_DESC_XSTATS_LEAF("mcast"),
 	.xstats_at = IFLA_STATS_LINK_XSTATS_SLAVE,
 	.link_type_at = LINK_XSTATS_TYPE_BRIDGE,
 	.inner_max = BRIDGE_XSTATS_MAX,
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH iproute2-next] ip: Convert non-constant initializers to macros
  2022-05-31 11:35 [PATCH iproute2-next] ip: Convert non-constant initializers to macros Petr Machata
@ 2022-05-31 14:12 ` Ido Schimmel
  0 siblings, 0 replies; 2+ messages in thread
From: Ido Schimmel @ 2022-05-31 14:12 UTC (permalink / raw)
  To: Petr Machata; +Cc: netdev, David Ahern, Tariq Toukan, Stephen Hemminger

On Tue, May 31, 2022 at 01:35:48PM +0200, Petr Machata wrote:
> As per the C standard, "expressions in an initializer for an object that
> has static or thread storage duration shall be constant expressions".
> Aggregate objects are not constant expressions. Newer GCC doesn't mind, but
> older GCC and LLVM do.
> 
> Therefore convert to a macro. And since all these macros will look very
> similar, extract a generic helper, IPSTATS_STAT_DESC_XSTATS_LEAF, which
> takes the leaf name as an argument and initializes the rest as appropriate
> for an xstats descriptor.
> 
> Reported-by: Stephen Hemminger <stephen@networkplumber.org>
> Signed-off-by: Petr Machata <petrm@nvidia.com>

Patch is directed at iproute2-next, but code is already in main branch

Fixes: d9976d671c37 ("ipstats: Expose bond stats in ipstats")
Fixes: 36e10429dafc ("ipstats: Expose bridge stats in ipstats")
Reviewed-by: Ido Schimmel <idosch@nvidia.com>

Fixes the build issue with clang on my laptop

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-31 14:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-31 11:35 [PATCH iproute2-next] ip: Convert non-constant initializers to macros Petr Machata
2022-05-31 14:12 ` Ido Schimmel

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.