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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <562b9a44ae5c6af4c801d8abf3a7cf318d2bfd32.1598210544.git.mkubecek@suse.cz>
Date:   Sun, 23 Aug 2020 21:40:36 +0200 (CEST)
From:   Michal Kubecek <mkubecek@...e.cz>
To:     netdev@...r.kernel.org
Cc:     Andrew Lunn <andrew@...n.ch>
Subject: [PATCH ethtool v2 7/9] settings: simplify link_mode_info[]
 initializers

Use macro helpers to make link_mode_info[] initializers easier to read and
less prone to mistakes. As a bonus, this gets rid of "missing field
initializer" warnings in netlink/settings.c

This commit should have no effect on resulting code (checked with gcc-11
and -O2).

Signed-off-by: Michal Kubecek <mkubecek@...e.cz>
Reviewed-by: Andrew Lunn <andrew@...n.ch>
---
 netlink/settings.c | 236 +++++++++++++++++----------------------------
 1 file changed, 86 insertions(+), 150 deletions(-)

diff --git a/netlink/settings.c b/netlink/settings.c
index 99d047a3e497..935724e799da 100644
--- a/netlink/settings.c
+++ b/netlink/settings.c
@@ -64,160 +64,96 @@ static const char *const names_transceiver[] = {
  * there is little chance of getting them separated any time soon so let's
  * sort them out ourselves
  */
+#define __REAL(_speed) \
+	{ .class = LM_CLASS_REAL, .speed = _speed, .duplex = DUPLEX_FULL }
+#define __HALF_DUPLEX(_speed) \
+	{ .class = LM_CLASS_REAL, .speed = _speed, .duplex = DUPLEX_HALF }
+#define __SPECIAL(_class) \
+	{ .class = LM_CLASS_ ## _class }
+
 static const struct link_mode_info link_modes[] = {
-	[ETHTOOL_LINK_MODE_10baseT_Half_BIT] =
-		{ LM_CLASS_REAL,	10,	DUPLEX_HALF },
-	[ETHTOOL_LINK_MODE_10baseT_Full_BIT] =
-		{ LM_CLASS_REAL,	10,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_100baseT_Half_BIT] =
-		{ LM_CLASS_REAL,	100,	DUPLEX_HALF },
-	[ETHTOOL_LINK_MODE_100baseT_Full_BIT] =
-		{ LM_CLASS_REAL,	100,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_1000baseT_Half_BIT] =
-		{ LM_CLASS_REAL,	1000,	DUPLEX_HALF },
-	[ETHTOOL_LINK_MODE_1000baseT_Full_BIT] =
-		{ LM_CLASS_REAL,	1000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_Autoneg_BIT] =
-		{ LM_CLASS_AUTONEG },
-	[ETHTOOL_LINK_MODE_TP_BIT] =
-		{ LM_CLASS_PORT },
-	[ETHTOOL_LINK_MODE_AUI_BIT] =
-		{ LM_CLASS_PORT },
-	[ETHTOOL_LINK_MODE_MII_BIT] =
-		{ LM_CLASS_PORT },
-	[ETHTOOL_LINK_MODE_FIBRE_BIT] =
-		{ LM_CLASS_PORT },
-	[ETHTOOL_LINK_MODE_BNC_BIT] =
-		{ LM_CLASS_PORT },
-	[ETHTOOL_LINK_MODE_10000baseT_Full_BIT] =
-		{ LM_CLASS_REAL,	10000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_Pause_BIT] =
-		{ LM_CLASS_PAUSE },
-	[ETHTOOL_LINK_MODE_Asym_Pause_BIT] =
-		{ LM_CLASS_PAUSE },
-	[ETHTOOL_LINK_MODE_2500baseX_Full_BIT] =
-		{ LM_CLASS_REAL,	2500,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_Backplane_BIT] =
-		{ LM_CLASS_PORT },
-	[ETHTOOL_LINK_MODE_1000baseKX_Full_BIT] =
-		{ LM_CLASS_REAL,	1000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT] =
-		{ LM_CLASS_REAL,	10000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_10000baseKR_Full_BIT] =
-		{ LM_CLASS_REAL,	10000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_10000baseR_FEC_BIT] =
-		{ LM_CLASS_REAL,	10000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT] =
-		{ LM_CLASS_REAL,	20000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT] =
-		{ LM_CLASS_REAL,	20000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT] =
-		{ LM_CLASS_REAL,	40000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT] =
-		{ LM_CLASS_REAL,	40000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT] =
-		{ LM_CLASS_REAL,	40000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT] =
-		{ LM_CLASS_REAL,	40000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT] =
-		{ LM_CLASS_REAL,	56000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT] =
-		{ LM_CLASS_REAL,	56000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT] =
-		{ LM_CLASS_REAL,	56000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT] =
-		{ LM_CLASS_REAL,	56000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_25000baseCR_Full_BIT] =
-		{ LM_CLASS_REAL,	25000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_25000baseKR_Full_BIT] =
-		{ LM_CLASS_REAL,	25000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_25000baseSR_Full_BIT] =
-		{ LM_CLASS_REAL,	25000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT] =
-		{ LM_CLASS_REAL,	50000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT] =
-		{ LM_CLASS_REAL,	50000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT] =
-		{ LM_CLASS_REAL,	100000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT] =
-		{ LM_CLASS_REAL,	100000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT] =
-		{ LM_CLASS_REAL,	100000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT] =
-		{ LM_CLASS_REAL,	100000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT] =
-		{ LM_CLASS_REAL,	50000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_1000baseX_Full_BIT] =
-		{ LM_CLASS_REAL,	1000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_10000baseCR_Full_BIT] =
-		{ LM_CLASS_REAL,	10000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_10000baseSR_Full_BIT] =
-		{ LM_CLASS_REAL,	10000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_10000baseLR_Full_BIT] =
-		{ LM_CLASS_REAL,	10000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT] =
-		{ LM_CLASS_REAL,	10000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_10000baseER_Full_BIT] =
-		{ LM_CLASS_REAL,	10000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_2500baseT_Full_BIT] =
-		{ LM_CLASS_REAL,	2500,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_5000baseT_Full_BIT] =
-		{ LM_CLASS_REAL,	5000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_FEC_NONE_BIT] =
-		{ LM_CLASS_FEC },
-	[ETHTOOL_LINK_MODE_FEC_RS_BIT] =
-		{ LM_CLASS_FEC },
-	[ETHTOOL_LINK_MODE_FEC_BASER_BIT] =
-		{ LM_CLASS_FEC },
-	[ETHTOOL_LINK_MODE_50000baseKR_Full_BIT] =
-		{ LM_CLASS_REAL,	50000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_50000baseSR_Full_BIT] =
-		{ LM_CLASS_REAL,	50000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_50000baseCR_Full_BIT] =
-		{ LM_CLASS_REAL,	50000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_50000baseLR_ER_FR_Full_BIT] =
-		{ LM_CLASS_REAL,	50000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_50000baseDR_Full_BIT] =
-		{ LM_CLASS_REAL,	50000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_100000baseKR2_Full_BIT] =
-		{ LM_CLASS_REAL,	100000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_100000baseSR2_Full_BIT] =
-		{ LM_CLASS_REAL,	100000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_100000baseCR2_Full_BIT] =
-		{ LM_CLASS_REAL,	100000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_100000baseLR2_ER2_FR2_Full_BIT] =
-		{ LM_CLASS_REAL,	100000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_100000baseDR2_Full_BIT] =
-		{ LM_CLASS_REAL,	100000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_200000baseKR4_Full_BIT] =
-		{ LM_CLASS_REAL,	200000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_200000baseSR4_Full_BIT] =
-		{ LM_CLASS_REAL,	200000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT] =
-		{ LM_CLASS_REAL,	200000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT] =
-		{ LM_CLASS_REAL,	200000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT] =
-		{ LM_CLASS_REAL,	200000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_100baseT1_Full_BIT] =
-		{ LM_CLASS_REAL,	100,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_1000baseT1_Full_BIT] =
-		{ LM_CLASS_REAL,	1000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_400000baseKR8_Full_BIT] =
-		{ LM_CLASS_REAL,	400000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_400000baseSR8_Full_BIT] =
-		{ LM_CLASS_REAL,	400000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_400000baseLR8_ER8_FR8_Full_BIT] =
-		{ LM_CLASS_REAL,	400000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_400000baseDR8_Full_BIT] =
-		{ LM_CLASS_REAL,	400000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_400000baseCR8_Full_BIT] =
-		{ LM_CLASS_REAL,	400000,	DUPLEX_FULL },
-	[ETHTOOL_LINK_MODE_FEC_LLRS_BIT] =
-		{ LM_CLASS_FEC },
+	[ETHTOOL_LINK_MODE_10baseT_Half_BIT]		= __HALF_DUPLEX(10),
+	[ETHTOOL_LINK_MODE_10baseT_Full_BIT]		= __REAL(10),
+	[ETHTOOL_LINK_MODE_100baseT_Half_BIT]		= __HALF_DUPLEX(100),
+	[ETHTOOL_LINK_MODE_100baseT_Full_BIT]		= __REAL(100),
+	[ETHTOOL_LINK_MODE_1000baseT_Half_BIT]		= __HALF_DUPLEX(1000),
+	[ETHTOOL_LINK_MODE_1000baseT_Full_BIT]		= __REAL(1000),
+	[ETHTOOL_LINK_MODE_Autoneg_BIT]			= __SPECIAL(AUTONEG),
+	[ETHTOOL_LINK_MODE_TP_BIT]			= __SPECIAL(PORT),
+	[ETHTOOL_LINK_MODE_AUI_BIT]			= __SPECIAL(PORT),
+	[ETHTOOL_LINK_MODE_MII_BIT]			= __SPECIAL(PORT),
+	[ETHTOOL_LINK_MODE_FIBRE_BIT]			= __SPECIAL(PORT),
+	[ETHTOOL_LINK_MODE_BNC_BIT]			= __SPECIAL(PORT),
+	[ETHTOOL_LINK_MODE_10000baseT_Full_BIT]		= __REAL(10000),
+	[ETHTOOL_LINK_MODE_Pause_BIT]			= __SPECIAL(PAUSE),
+	[ETHTOOL_LINK_MODE_Asym_Pause_BIT]		= __SPECIAL(PAUSE),
+	[ETHTOOL_LINK_MODE_2500baseX_Full_BIT]		= __REAL(2500),
+	[ETHTOOL_LINK_MODE_Backplane_BIT]		= __SPECIAL(PORT),
+	[ETHTOOL_LINK_MODE_1000baseKX_Full_BIT]		= __REAL(1000),
+	[ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT]	= __REAL(10000),
+	[ETHTOOL_LINK_MODE_10000baseKR_Full_BIT]	= __REAL(10000),
+	[ETHTOOL_LINK_MODE_10000baseR_FEC_BIT]		= __REAL(10000),
+	[ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT]	= __REAL(20000),
+	[ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT]	= __REAL(20000),
+	[ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT]	= __REAL(40000),
+	[ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT]	= __REAL(40000),
+	[ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT]	= __REAL(40000),
+	[ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT]	= __REAL(40000),
+	[ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT]	= __REAL(56000),
+	[ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT]	= __REAL(56000),
+	[ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT]	= __REAL(56000),
+	[ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT]	= __REAL(56000),
+	[ETHTOOL_LINK_MODE_25000baseCR_Full_BIT]	= __REAL(25000),
+	[ETHTOOL_LINK_MODE_25000baseKR_Full_BIT]	= __REAL(25000),
+	[ETHTOOL_LINK_MODE_25000baseSR_Full_BIT]	= __REAL(25000),
+	[ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT]	= __REAL(50000),
+	[ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT]	= __REAL(50000),
+	[ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT]	= __REAL(100000),
+	[ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT]	= __REAL(100000),
+	[ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT]	= __REAL(100000),
+	[ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT]	= __REAL(100000),
+	[ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT]	= __REAL(50000),
+	[ETHTOOL_LINK_MODE_1000baseX_Full_BIT]		= __REAL(1000),
+	[ETHTOOL_LINK_MODE_10000baseCR_Full_BIT]	= __REAL(10000),
+	[ETHTOOL_LINK_MODE_10000baseSR_Full_BIT]	= __REAL(10000),
+	[ETHTOOL_LINK_MODE_10000baseLR_Full_BIT]	= __REAL(10000),
+	[ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT]	= __REAL(10000),
+	[ETHTOOL_LINK_MODE_10000baseER_Full_BIT]	= __REAL(10000),
+	[ETHTOOL_LINK_MODE_2500baseT_Full_BIT]		= __REAL(2500),
+	[ETHTOOL_LINK_MODE_5000baseT_Full_BIT]		= __REAL(5000),
+	[ETHTOOL_LINK_MODE_FEC_NONE_BIT]		= __SPECIAL(FEC),
+	[ETHTOOL_LINK_MODE_FEC_RS_BIT]			= __SPECIAL(FEC),
+	[ETHTOOL_LINK_MODE_FEC_BASER_BIT]		= __SPECIAL(FEC),
+	[ETHTOOL_LINK_MODE_50000baseKR_Full_BIT]	= __REAL(50000),
+	[ETHTOOL_LINK_MODE_50000baseSR_Full_BIT]	= __REAL(50000),
+	[ETHTOOL_LINK_MODE_50000baseCR_Full_BIT]	= __REAL(50000),
+	[ETHTOOL_LINK_MODE_50000baseLR_ER_FR_Full_BIT]	= __REAL(50000),
+	[ETHTOOL_LINK_MODE_50000baseDR_Full_BIT]	= __REAL(50000),
+	[ETHTOOL_LINK_MODE_100000baseKR2_Full_BIT]	= __REAL(100000),
+	[ETHTOOL_LINK_MODE_100000baseSR2_Full_BIT]	= __REAL(100000),
+	[ETHTOOL_LINK_MODE_100000baseCR2_Full_BIT]	= __REAL(100000),
+	[ETHTOOL_LINK_MODE_100000baseLR2_ER2_FR2_Full_BIT] = __REAL(100000),
+	[ETHTOOL_LINK_MODE_100000baseDR2_Full_BIT]	= __REAL(100000),
+	[ETHTOOL_LINK_MODE_200000baseKR4_Full_BIT]	= __REAL(200000),
+	[ETHTOOL_LINK_MODE_200000baseSR4_Full_BIT]	= __REAL(200000),
+	[ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT] = __REAL(200000),
+	[ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT]	= __REAL(200000),
+	[ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT]	= __REAL(200000),
+	[ETHTOOL_LINK_MODE_100baseT1_Full_BIT]		= __REAL(100),
+	[ETHTOOL_LINK_MODE_1000baseT1_Full_BIT]		= __REAL(1000),
+	[ETHTOOL_LINK_MODE_400000baseKR8_Full_BIT]	= __REAL(400000),
+	[ETHTOOL_LINK_MODE_400000baseSR8_Full_BIT]	= __REAL(400000),
+	[ETHTOOL_LINK_MODE_400000baseLR8_ER8_FR8_Full_BIT] = __REAL(400000),
+	[ETHTOOL_LINK_MODE_400000baseDR8_Full_BIT]	= __REAL(400000),
+	[ETHTOOL_LINK_MODE_400000baseCR8_Full_BIT]	= __REAL(400000),
+	[ETHTOOL_LINK_MODE_FEC_LLRS_BIT]		= __SPECIAL(FEC),
 };
 const unsigned int link_modes_count = ARRAY_SIZE(link_modes);
 
+#undef __REAL
+#undef __HALF_DUPLEX
+#undef __SPECIAL
+
 static bool lm_class_match(unsigned int mode, enum link_mode_class class)
 {
 	unsigned int mode_class = (mode < link_modes_count) ?
-- 
2.28.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ