[PATCHv3 13/15] staging: rtl8192u: r8192U_core: rtl8192_ioctl: reorganize function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Reorganize function rtl8192_ioctl to replace a switch with only
one case besides the default by an if statement. This also allows
to follow the 80 characters kernel code style rule.

Signed-off-by: Raphaël Beamonte <raphael.beamonte@xxxxxxxxx>
---
 drivers/staging/rtl8192u/r8192U_core.c | 141 ++++++++++++++++-----------------
 1 file changed, 68 insertions(+), 73 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
index 7dc1b34..171a494 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -3751,82 +3751,77 @@ static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 		goto out;
 	}
 
-	switch (cmd) {
-	case RTL_IOCTL_WPA_SUPPLICANT:
-		/* parse here for HW security */
-		if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION) {
-			if (ipw->u.crypt.set_tx) {
-				if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) {
-					ieee->pairwise_key_type = KEY_TYPE_CCMP;
-				} else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) {
-					ieee->pairwise_key_type = KEY_TYPE_TKIP;
-				} else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
-					if (ipw->u.crypt.key_len == 13)
-						ieee->pairwise_key_type = KEY_TYPE_WEP104;
-					else if (ipw->u.crypt.key_len == 5)
-						ieee->pairwise_key_type = KEY_TYPE_WEP40;
-				} else {
-					ieee->pairwise_key_type = KEY_TYPE_NA;
-				}
-
-				if (ieee->pairwise_key_type) {
-					memcpy((u8 *)key, ipw->u.crypt.key, 16);
-					EnableHWSecurityConfig8192(dev);
-					/* We fill both index entry and 4th
-					 * entry for pairwise key as in IPW
-					 * interface, adhoc will only get here,
-					 * so we need index entry for its
-					 * default key serching!
-					 */
-					setKey(dev, 4, ipw->u.crypt.idx,
-					       ieee->pairwise_key_type,
-					       (u8 *)ieee->ap_mac_addr,
-					       0, key);
-					if (ieee->auth_mode != 2)
-						setKey(dev, ipw->u.crypt.idx,
-						       ipw->u.crypt.idx,
-						       ieee->pairwise_key_type,
-						       (u8 *)ieee->ap_mac_addr,
-						       0, key);
-				}
-			} else {
-				memcpy((u8 *)key, ipw->u.crypt.key, 16);
-				if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) {
-					ieee->group_key_type = KEY_TYPE_CCMP;
-				} else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) {
-					ieee->group_key_type = KEY_TYPE_TKIP;
-				} else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
-					if (ipw->u.crypt.key_len == 13)
-						ieee->group_key_type = KEY_TYPE_WEP104;
-					else if (ipw->u.crypt.key_len == 5)
-						ieee->group_key_type = KEY_TYPE_WEP40;
-				} else {
-					ieee->group_key_type = KEY_TYPE_NA;
-				}
-
-				if (ieee->group_key_type) {
-					setKey(dev, ipw->u.crypt.idx,
-					       /* KeyIndex */
-					       ipw->u.crypt.idx,
-					       /* KeyType */
-					       ieee->group_key_type,
-					       /* MacAddr */
-					       broadcast_addr,
-					       /* DefaultKey */
-					       0,
-					       /* KeyContent */
-					       key);
-				}
-			}
+	if (cmd != RTL_IOCTL_WPA_SUPPLICANT) {
+		ret = -EOPNOTSUPP;
+		goto kfree;
+	}
+
+	/* parse here for HW security */
+	if (ipw->cmd != IEEE_CMD_SET_ENCRYPTION)
+		goto ret;
+
+	if (ipw->u.crypt.set_tx) {
+		if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) {
+			ieee->pairwise_key_type = KEY_TYPE_CCMP;
+		} else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) {
+			ieee->pairwise_key_type = KEY_TYPE_TKIP;
+		} else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
+			if (ipw->u.crypt.key_len == 13)
+				ieee->pairwise_key_type = KEY_TYPE_WEP104;
+			else if (ipw->u.crypt.key_len == 5)
+				ieee->pairwise_key_type = KEY_TYPE_WEP40;
+		} else {
+			ieee->pairwise_key_type = KEY_TYPE_NA;
 		}
-		ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211,
-						     &wrq->u.data);
-		break;
 
-	default:
-		ret = -EOPNOTSUPP;
-		break;
+		if (ieee->pairwise_key_type) {
+			memcpy((u8 *)key, ipw->u.crypt.key, 16);
+			EnableHWSecurityConfig8192(dev);
+			/* We fill both index entry and 4th
+			 * entry for pairwise key as in IPW
+			 * interface, adhoc will only get here,
+			 * so we need index entry for its
+			 * default key serching!
+			 */
+			setKey(dev, 4, ipw->u.crypt.idx,
+			       ieee->pairwise_key_type,
+			       (u8 *)ieee->ap_mac_addr, 0, key);
+			if (ieee->auth_mode != 2)
+				setKey(dev, ipw->u.crypt.idx, ipw->u.crypt.idx,
+				       ieee->pairwise_key_type,
+				       (u8 *)ieee->ap_mac_addr, 0, key);
+		}
+	} else {
+		memcpy((u8 *)key, ipw->u.crypt.key, 16);
+		if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) {
+			ieee->group_key_type = KEY_TYPE_CCMP;
+		} else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) {
+			ieee->group_key_type = KEY_TYPE_TKIP;
+		} else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
+			if (ipw->u.crypt.key_len == 13)
+				ieee->group_key_type = KEY_TYPE_WEP104;
+			else if (ipw->u.crypt.key_len == 5)
+				ieee->group_key_type = KEY_TYPE_WEP40;
+		} else {
+			ieee->group_key_type = KEY_TYPE_NA;
+		}
+
+		if (ieee->group_key_type) {
+			setKey(dev, ipw->u.crypt.idx,
+			       ipw->u.crypt.idx, /* KeyIndex */
+			       ieee->group_key_type, /* KeyType */
+			       broadcast_addr, /* MacAddr */
+			       0, /* DefaultKey */
+			       key); /* KeyContent */
+
+		}
 	}
+
+ret:
+	ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211,
+					     &wrq->u.data);
+
+kfree:
 	kfree(ipw);
 	ipw = NULL;
 out:
-- 
2.5.1

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux