Wireless Daemon for Linux
 help / color / mirror / Atom feed
* [PATCH v2 01/13] wiphy: fix runtime error from bit shift
@ 2022-08-03 21:36 James Prestwood
  2022-08-03 21:36 ` [PATCH v2 02/13] scan: track scanned frequencies for entire request James Prestwood
                   ` (11 more replies)
  0 siblings, 12 replies; 16+ messages in thread
From: James Prestwood @ 2022-08-03 21:36 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

The compiler treated the '1' as an int type which was not big enough
to hold a bit shift of 31:

runtime error: left shift of 1 by 31 places cannot be represented in
		type 'int'

Instead of doing the iftype check manually, refactor
wiphy_get_supported_iftypes by adding a subroutine which just parses
out iftypes from a mask into a char** list. This removes the need to
case each iftype into a string.
---
 src/wiphy.c | 50 +++++++++++++++-----------------------------------
 1 file changed, 15 insertions(+), 35 deletions(-)

diff --git a/src/wiphy.c b/src/wiphy.c
index 026605fe..2514c95a 100644
--- a/src/wiphy.c
+++ b/src/wiphy.c
@@ -716,17 +716,16 @@ bool wiphy_constrain_freq_set(const struct wiphy *wiphy,
 	return true;
 }
 
-static char **wiphy_get_supported_iftypes(struct wiphy *wiphy, uint16_t mask)
+static char **wiphy_iftype_mask_to_str(uint16_t mask)
 {
-	uint16_t supported_mask = wiphy->supported_iftypes & mask;
-	char **ret = l_new(char *, __builtin_popcount(supported_mask) + 1);
+	char **ret = l_new(char *, __builtin_popcount(mask) + 1);
 	unsigned int i;
 	unsigned int j;
 
-	for (j = 0, i = 0; i < sizeof(supported_mask) * 8; i++) {
+	for (j = 0, i = 0; i < sizeof(mask) * 8; i++) {
 		const char *str;
 
-		if (!(supported_mask & (1 << i)))
+		if (!(mask & (1 << i)))
 			continue;
 
 		str = netdev_iftype_to_string(i + 1);
@@ -737,6 +736,11 @@ static char **wiphy_get_supported_iftypes(struct wiphy *wiphy, uint16_t mask)
 	return ret;
 }
 
+static char **wiphy_get_supported_iftypes(struct wiphy *wiphy, uint16_t mask)
+{
+	return wiphy_iftype_mask_to_str(wiphy->supported_iftypes & mask);
+}
+
 bool wiphy_supports_iftype(struct wiphy *wiphy, uint32_t iftype)
 {
 	if (iftype > sizeof(wiphy->supported_iftypes) * 8)
@@ -960,38 +964,14 @@ static void wiphy_print_mcs_info(const uint8_t *mcs_map,
 static void wiphy_print_he_capabilities(struct band *band,
 				const struct band_he_capabilities *he_cap)
 {
-	int i;
-	char type_buf[128];
-	char *s = type_buf;
+	_auto_(l_strv_free) char **iftypes = NULL;
+	_auto_(l_free) char *joined = NULL;
 	uint8_t width_set = bit_field(he_cap->he_phy_capa[0], 1, 7);
 
-	for (i = 0; i < 32; i++) {
-		if (!(he_cap->iftypes & (1 << i)))
-			continue;
-
-		if (L_WARN_ON(s >= type_buf + sizeof(type_buf)))
-			return;
-
-		switch (i) {
-		case NETDEV_IFTYPE_ADHOC:
-			s += sprintf(s, "%s ", "Ad-Hoc");
-			break;
-		case NETDEV_IFTYPE_STATION:
-			s += sprintf(s, "%s ", "Station");
-			break;
-		case NETDEV_IFTYPE_AP:
-			s += sprintf(s, "%s ", "AP");
-			break;
-		case NETDEV_IFTYPE_P2P_CLIENT:
-			s += sprintf(s, "%s ", "P2P Client");
-			break;
-		case NETDEV_IFTYPE_P2P_GO:
-			s += sprintf(s, "%s ", "P2P GO");
-			break;
-		}
-	}
+	iftypes = wiphy_iftype_mask_to_str(he_cap->iftypes);
+	joined = l_strjoinv(iftypes, ' ');
 
-	l_info("\t\t\tInterface Types: %s", type_buf);
+	l_info("\t\t\tInterface Types: %s", joined);
 
 	switch (band->freq) {
 	case BAND_FREQ_2_4_GHZ:
@@ -1341,7 +1321,7 @@ static uint32_t get_iftypes(struct l_genl_attr *iftypes)
 		if (len != 0)
 			continue;
 
-		types |= (1 << type);
+		types |= (1 << (type - 1));
 	}
 
 	return types;
-- 
2.34.3


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

end of thread, other threads:[~2022-08-04 17:06 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-03 21:36 [PATCH v2 01/13] wiphy: fix runtime error from bit shift James Prestwood
2022-08-03 21:36 ` [PATCH v2 02/13] scan: track scanned frequencies for entire request James Prestwood
2022-08-03 21:36 ` [PATCH v2 03/13] nl80211util: add nl80211_parse_supported_frequencies James Prestwood
2022-08-04 15:27   ` Denis Kenzior
2022-08-03 21:36 ` [PATCH v2 04/13] wiphy: track self-managed flag James Prestwood
2022-08-03 21:36 ` [PATCH v2 05/13] wiphy: use nl80211_parse_supported_frequencies James Prestwood
2022-08-03 21:36 ` [PATCH v2 06/13] wiphy: add two regulatory domain state events James Prestwood
2022-08-04 15:31   ` Denis Kenzior
2022-08-03 21:36 ` [PATCH v2 07/13] wiphy: dump wiphy's on regulatory domain change James Prestwood
2022-08-03 21:36 ` [PATCH v2 08/13] wiphy: add wiphy_regdom_is_updating James Prestwood
2022-08-03 21:36 ` [PATCH v2 09/13] wiphy: add wiphy_country_is_unknown James Prestwood
2022-08-04 16:48   ` Denis Kenzior
2022-08-03 21:36 ` [PATCH v2 10/13] station: do full passive scan if 6GHz is supported but disabled James Prestwood
2022-08-03 21:36 ` [PATCH v2 11/13] scan: split full scans by band to enable 6GHz James Prestwood
2022-08-03 21:36 ` [PATCH v2 12/13] scan: watch for regdom updates " James Prestwood
2022-08-03 21:36 ` [PATCH v2 13/13] wiphy: don't re-dump wiphy if the regdom didn't change James Prestwood

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox