linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] Staging: wlan-ng: replace switch-case statements with macro
@ 2016-08-26 17:58 Claudiu Beznea
  2016-08-26 18:07 ` Joe Perches
  0 siblings, 1 reply; 3+ messages in thread
From: Claudiu Beznea @ 2016-08-26 17:58 UTC (permalink / raw)
  To: gregkh; +Cc: devel, linux-kernel, Claudiu Beznea

This patch removes multiple switch-case statements
with a new macro. The macro will generate the
corresponding bit mask based on the key index
received as input.

Chances since v1:
Corrected patch title

Signed-off-by: Claudiu Beznea <claudiu.beznea@gmail.com>
---
 drivers/staging/wlan-ng/cfg80211.c      | 85 ++++++---------------------------
 drivers/staging/wlan-ng/p80211metadef.h |  4 ++
 2 files changed, 19 insertions(+), 70 deletions(-)

diff --git a/drivers/staging/wlan-ng/cfg80211.c b/drivers/staging/wlan-ng/cfg80211.c
index f46dfe6..73ba264 100644
--- a/drivers/staging/wlan-ng/cfg80211.c
+++ b/drivers/staging/wlan-ng/cfg80211.c
@@ -150,6 +150,9 @@ static int prism2_add_key(struct wiphy *wiphy, struct net_device *dev,
 	int err = 0;
 	int result = 0;
 
+	if (key_index >= NUM_WEPKEYS)
+		return -EINVAL;
+
 	switch (params->cipher) {
 	case WLAN_CIPHER_SUITE_WEP40:
 	case WLAN_CIPHER_SUITE_WEP104:
@@ -160,27 +163,7 @@ static int prism2_add_key(struct wiphy *wiphy, struct net_device *dev,
 			goto exit;
 
 		/* send key to driver */
-		switch (key_index) {
-		case 0:
-			did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0;
-			break;
-
-		case 1:
-			did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1;
-			break;
-
-		case 2:
-			did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2;
-			break;
-
-		case 3:
-			did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3;
-			break;
-
-		default:
-			err = -EINVAL;
-			goto exit;
-		}
+		did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(key_index + 1);
 
 		result = prism2_domibset_pstr32(wlandev, did,
 						params->key_len, params->key);
@@ -242,36 +225,13 @@ static int prism2_del_key(struct wiphy *wiphy, struct net_device *dev,
 	 * a key, so we will cheat by setting the key to a bogus value
 	 */
 
-	/* send key to driver */
-	switch (key_index) {
-	case 0:
-		did =
-		    DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0;
-		break;
-
-	case 1:
-		did =
-		    DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1;
-		break;
-
-	case 2:
-		did =
-		    DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2;
-		break;
-
-	case 3:
-		did =
-		    DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3;
-		break;
-
-	default:
-		err = -EINVAL;
-		goto exit;
-	}
+	if (key_index >= NUM_WEPKEYS)
+		return -EINVAL;
 
+	/* send key to driver */
+	did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(key_index + 1);
 	result = prism2_domibset_pstr32(wlandev, did, 13, "0000000000000");
 
-exit:
 	if (result)
 		err = -EFAULT;
 
@@ -529,6 +489,11 @@ static int prism2_connect(struct wiphy *wiphy, struct net_device *dev,
 	/* Set the encryption - we only support wep */
 	if (is_wep) {
 		if (sme->key) {
+			if (sme->key_idx >= NUM_WEPKEYS) {
+				err = -EINVAL;
+				goto exit;
+			}
+
 			result = prism2_domibset_uint32(wlandev,
 				DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID,
 				sme->key_idx);
@@ -536,28 +501,8 @@ static int prism2_connect(struct wiphy *wiphy, struct net_device *dev,
 				goto exit;
 
 			/* send key to driver */
-			switch (sme->key_idx) {
-			case 0:
-				did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0;
-				break;
-
-			case 1:
-				did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1;
-				break;
-
-			case 2:
-				did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2;
-				break;
-
-			case 3:
-				did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3;
-				break;
-
-			default:
-				err = -EINVAL;
-				goto exit;
-			}
-
+			did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(
+					sme->key_idx + 1);
 			result = prism2_domibset_pstr32(wlandev,
 							did, sme->key_len,
 							(u8 *)sme->key);
diff --git a/drivers/staging/wlan-ng/p80211metadef.h b/drivers/staging/wlan-ng/p80211metadef.h
index 0ccfba1..98fda3d 100644
--- a/drivers/staging/wlan-ng/p80211metadef.h
+++ b/drivers/staging/wlan-ng/p80211metadef.h
@@ -171,6 +171,10 @@
 			(P80211DID_MKSECTION(1) | \
 			P80211DID_MKGROUP(4) | \
 			P80211DID_MKITEM(4) | 0x0c000000)
+#define DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(_i) \
+			(P80211DID_MKSECTION(1) | \
+			P80211DID_MKGROUP(4) | \
+			P80211DID_MKITEM(_i) | 0x0c000000)
 #define DIDmib_dot11smt_dot11PrivacyTable \
 			(P80211DID_MKSECTION(1) | \
 			P80211DID_MKGROUP(6))
-- 
1.9.1

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

* Re: [PATCH v2] Staging: wlan-ng: replace switch-case statements with macro
  2016-08-26 17:58 [PATCH v2] Staging: wlan-ng: replace switch-case statements with macro Claudiu Beznea
@ 2016-08-26 18:07 ` Joe Perches
  2016-08-26 18:40   ` Claudiu Beznea
  0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2016-08-26 18:07 UTC (permalink / raw)
  To: Claudiu Beznea, gregkh; +Cc: devel, linux-kernel

On Fri, 2016-08-26 at 20:58 +0300, Claudiu Beznea wrote:
> This patch removes multiple switch-case statements
> with a new macro. The macro will generate the
> corresponding bit mask based on the key index
> received as input.

Can you go a little farther and remove the
#define DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey<#>
and uses too?

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

* Re: [PATCH v2] Staging: wlan-ng: replace switch-case statements with macro
  2016-08-26 18:07 ` Joe Perches
@ 2016-08-26 18:40   ` Claudiu Beznea
  0 siblings, 0 replies; 3+ messages in thread
From: Claudiu Beznea @ 2016-08-26 18:40 UTC (permalink / raw)
  To: Joe Perches; +Cc: Greg KH, devel, linux-kernel

I will do it soon.

Thanks,
Claudiu

On Fri, Aug 26, 2016 at 9:07 PM, Joe Perches <joe@perches.com> wrote:
> On Fri, 2016-08-26 at 20:58 +0300, Claudiu Beznea wrote:
>> This patch removes multiple switch-case statements
>> with a new macro. The macro will generate the
>> corresponding bit mask based on the key index
>> received as input.
>
> Can you go a little farther and remove the
> #define DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey<#>
> and uses too?
>

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

end of thread, other threads:[~2016-08-26 18:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-26 17:58 [PATCH v2] Staging: wlan-ng: replace switch-case statements with macro Claudiu Beznea
2016-08-26 18:07 ` Joe Perches
2016-08-26 18:40   ` Claudiu Beznea

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).