Skip to contentSkip to conversation

Staging: vt6655: Replace switch by if-else statement

PATCH In review Ksenija Stanojevic 2 participants 3 messages Oct 8, 2015 1 message not in the archive Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: vt6655: Replace switch by if-else statement

Use of switch statement is wrong here, better use if-else statement instead.

---
 drivers/staging/vt6655/channel.c | 33 +++++++++++++--------------------
 1 file changed, 13 insertions(+), 20 deletions(-)
drivers/staging/vt6655/channel.c +13 -20
index 7a71782..3d12da6 100644
@@ -132,26 +132,10 @@ void vnt_init_bands(struct vnt_private *priv)
 	struct ieee80211_channel *ch;
 	int i;
 
-	switch (priv->byRFType) {
-	case RF_AIROHA7230:
-	case RF_UW2452:
-	case RF_NOTHING:
-	default:
-		ch = vnt_channels_5ghz;
+	if (priv->byRFType == RF_RFMD2959 || priv->byRFType == RF_AIROHA ||
+	    priv->byRFType == RF_AL2230S || priv->byRFType == RF_UW2451 ||
+	    priv->byRFType == RF_VT3226) {
 
-		for (i = 0; i < ARRAY_SIZE(vnt_channels_5ghz); i++) {
-			ch[i].max_power = 0x3f;
-			ch[i].flags = IEEE80211_CHAN_NO_HT40;
-		}
-
-		priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
-						&vnt_supported_5ghz_band;
-	/* fallthrough */
-	case RF_RFMD2959:
-	case RF_AIROHA:
-	case RF_AL2230S:
-	case RF_UW2451:
-	case RF_VT3226:
 		ch = vnt_channels_2ghz;
 
 		for (i = 0; i < ARRAY_SIZE(vnt_channels_2ghz); i++) {
@@ -161,7 +145,16 @@ void vnt_init_bands(struct vnt_private *priv)
 
 		priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
 						&vnt_supported_2ghz_band;
-		break;
+	} else {
+		ch = vnt_channels_5ghz;
+
+		for (i = 0; i < ARRAY_SIZE(vnt_channels_5ghz); i++) {
+			ch[i].max_power = 0x3f;
+			ch[i].flags = IEEE80211_CHAN_NO_HT40;
+		}
+
+		priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
+						&vnt_supported_5ghz_band;
 	}
 }
 
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 2 lines · Ksenija Stanojevic

Use of switch statement is wrong here, better use if-else statement instead.

Why is it "wrong"? It looks cleaner to me as a switch statement, easier to read and understand. Why change it?

Quoted 13 lines
---
 drivers/staging/vt6655/channel.c | 33 +++++++++++++--------------------
 1 file changed, 13 insertions(+), 20 deletions(-)
drivers/staging/vt6655/channel.c +0 -0
index 7a71782..3d12da6 100644
@@ -132,26 +132,10 @@ void vnt_init_bands(struct vnt_private *priv)
 	struct ieee80211_channel *ch;
 	int i;

drivers/staging/vt6655/channel.c void vnt_init_bands(struct vnt_private *priv) · line 137

Quoted 10 lines
drivers/staging/vt6655/channel.c +3 -6
 
-	switch (priv->byRFType) {
-	case RF_AIROHA7230:
-	case RF_UW2452:
-	case RF_NOTHING:
-	default:
-		ch = vnt_channels_5ghz;
+	if (priv->byRFType == RF_RFMD2959 || priv->byRFType == RF_AIROHA ||
+	    priv->byRFType == RF_AL2230S || priv->byRFType == RF_UW2451 ||
+	    priv->byRFType == RF_VT3226) {

That's hard to read which types are and are not included here, right?

Quoted 22 lines
drivers/staging/vt6655/channel.c +0 -14
-		for (i = 0; i < ARRAY_SIZE(vnt_channels_5ghz); i++) {
-			ch[i].max_power = 0x3f;
-			ch[i].flags = IEEE80211_CHAN_NO_HT40;
-		}
-
-		priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
-						&vnt_supported_5ghz_band;
-	/* fallthrough */
-	case RF_RFMD2959:
-	case RF_AIROHA:
-	case RF_AL2230S:
-	case RF_UW2451:
-	case RF_VT3226:
 		ch = vnt_channels_2ghz;
 
 		for (i = 0; i < ARRAY_SIZE(vnt_channels_2ghz); i++) {
@@ -161,7 +145,16 @@ void vnt_init_bands(struct vnt_private *priv)
 
 		priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
 						&vnt_supported_2ghz_band;
-		break;

drivers/staging/vt6655/channel.c void vnt_init_bands(struct vnt_private *priv) · line 157

Quoted 10 lines
drivers/staging/vt6655/channel.c +10 -0
+	} else {
+		ch = vnt_channels_5ghz;
+
+		for (i = 0; i < ARRAY_SIZE(vnt_channels_5ghz); i++) {
+			ch[i].max_power = 0x3f;
+			ch[i].flags = IEEE80211_CHAN_NO_HT40;
+		}
+
+		priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
+						&vnt_supported_5ghz_band;

I think you are changing the logic here a bit, are you sure it's still identical?

thanks,

greg k-h

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 54 lines · Greg KH
Quoted 2 lines · Ksenija Stanojevic

Use of switch statement is wrong here, better use if-else statement instead.

Why is it "wrong"? It looks cleaner to me as a switch statement, easier to read and understand. Why change it?

Quoted 13 lines
---
 drivers/staging/vt6655/channel.c | 33 +++++++++++++--------------------
 1 file changed, 13 insertions(+), 20 deletions(-)
drivers/staging/vt6655/channel.c +0 -0
index 7a71782..3d12da6 100644
@@ -132,26 +132,10 @@ void vnt_init_bands(struct vnt_private *priv)
      struct ieee80211_channel *ch;
      int i;

drivers/staging/vt6655/channel.c void vnt_init_bands(struct vnt_private *priv) · line 137

Quoted 10 lines
drivers/staging/vt6655/channel.c +3 -6
 
-     switch (priv->byRFType) {
-     case RF_AIROHA7230:
-     case RF_UW2452:
-     case RF_NOTHING:
-     default:
-             ch = vnt_channels_5ghz;
+     if (priv->byRFType == RF_RFMD2959 || priv->byRFType == RF_AIROHA ||
+         priv->byRFType == RF_AL2230S || priv->byRFType == RF_UW2451 ||
+         priv->byRFType == RF_VT3226) {

That's hard to read which types are and are not included here, right?

Quoted 19 lines
drivers/staging/vt6655/channel.c +0 -13
-             for (i = 0; i < ARRAY_SIZE(vnt_channels_5ghz); i++) {
-                     ch[i].max_power = 0x3f;
-                     ch[i].flags = IEEE80211_CHAN_NO_HT40;
-             }
-
-             priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
-                                             &vnt_supported_5ghz_band;
-     /* fallthrough */
-     case RF_RFMD2959:
-     case RF_AIROHA:
-     case RF_AL2230S:
-     case RF_UW2451:
-     case RF_VT3226:
              ch = vnt_channels_2ghz;
 
              for (i = 0; i < ARRAY_SIZE(vnt_channels_2ghz); i++) {
@@ -161,7 +145,16 @@ void vnt_init_bands(struct vnt_private *priv)
 
Quoted 16 lines

drivers/staging/vt6655/channel.c void vnt_init_bands(struct vnt_private *priv) · line 157

Quoted 13 lines
drivers/staging/vt6655/channel.c +10 -1
              priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
                                              &vnt_supported_2ghz_band;
-             break;
+     } else {
+             ch = vnt_channels_5ghz;
+
+             for (i = 0; i < ARRAY_SIZE(vnt_channels_5ghz); i++) {
+                     ch[i].max_power = 0x3f;
+                     ch[i].flags = IEEE80211_CHAN_NO_HT40;
+             }
+
+             priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
+                                             &vnt_supported_5ghz_band;

I think you are changing the logic here a bit, are you sure it's still identical?

Break is missing so I thought that in cases
RF_RFMD2959, RF_AIROHA, RF_AL2230S, RF_UW2451, RF_VT3226
ch and priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] will be overwritten but I see now that in that part of the code priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] is used, so the change is not correct

Ksenija