]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip: Convert non-constant initializers to macros
authorPetr Machata <petrm@nvidia.com>
Tue, 31 May 2022 11:35:48 +0000 (13:35 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Wed, 1 Jun 2022 23:01:14 +0000 (16:01 -0700)
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>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
ip/ip_common.h
ip/iplink_bond.c
ip/iplink_bridge.c

index ffa633e0997034a2f59873df55d24fa5ecffa3c1..c4cb1bcb1e3a78ab504a1ef9d9c5980f2a176a09 100644 (file)
@@ -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
index 15db19a3d3c2b0b2ff91474b46d029a92fb648b0..7943499e0adfc5df101d19814c473b464ee407df 100644 (file)
@@ -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,
index 3feb6109f08336af384e46d01779e775c230195e..0f950d3772f9406d50f72d624c0b22ed26b69964 100644 (file)
@@ -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,