lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 31 May 2022 13:35:48 +0200
From:   Petr Machata <petrm@...dia.com>
To:     <netdev@...r.kernel.org>
CC:     David Ahern <dsahern@...il.com>, Ido Schimmel <idosch@...dia.com>,
        "Tariq Toukan" <tariqt@...dia.com>,
        Petr Machata <petrm@...dia.com>,
        "Stephen Hemminger" <stephen@...workplumber.org>
Subject: [PATCH iproute2-next] ip: Convert non-constant initializers to macros

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@...workplumber.org>
Signed-off-by: Petr Machata <petrm@...dia.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ