All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Tobin C. Harding" <me@tobin.cc>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Tobin C. Harding" <me@tobin.cc>,
	Wolfram Sang <wsa@the-dreams.de>,
	driverdev-devel@linuxdriverproject.org
Subject: [PATCH 11/12] staging: ks7010: reduce level of indentation
Date: Tue, 14 Mar 2017 09:54:09 +1100	[thread overview]
Message-ID: <1489445650-11398-12-git-send-email-me@tobin.cc> (raw)
In-Reply-To: <1489445650-11398-1-git-send-email-me@tobin.cc>

Checkpatch emits WARNING: Too many leading tabs - consider code
refactoring. One level of indentation may be removed by inverting an
if statement conditional (and returning if new conditional evaluates
to true). Code contains switch statement that also contains multiple
layers of indentation. Indentation may be reduced by breaking out of
the case statement in multiple places instead of guarding code with
if/else statements.

Invert conditional. Return original error code if new conditional
evaluates to true. Break out of case blocks instead of using
if/else. Do not modify program logic.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
---
 drivers/staging/ks7010/ks_wlan_net.c | 195 ++++++++++++++++++-----------------
 1 file changed, 98 insertions(+), 97 deletions(-)

diff --git a/drivers/staging/ks7010/ks_wlan_net.c b/drivers/staging/ks7010/ks_wlan_net.c
index bb20bb9..ca46869 100644
--- a/drivers/staging/ks7010/ks_wlan_net.c
+++ b/drivers/staging/ks7010/ks_wlan_net.c
@@ -2004,72 +2004,71 @@ static int ks_wlan_set_encode_ext(struct net_device *dev,
 	if (dwrq->flags & IW_ENCODE_DISABLED)
 		priv->wpa.key[index].key_len = 0;
 
-	if (enc) {
-		priv->wpa.key[index].ext_flags = enc->ext_flags;
-		if (enc->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
-			priv->wpa.txkey = index;
-			commit |= SME_WEP_INDEX;
-		} else if (enc->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
-			memcpy(&priv->wpa.key[index].rx_seq[0],
-			       enc->rx_seq, IW_ENCODE_SEQ_MAX_SIZE);
-		}
+	if (!enc)
+		return -EINVAL;
 
-		memcpy(&priv->wpa.key[index].addr.sa_data[0],
-		       &enc->addr.sa_data[0], ETH_ALEN);
+	priv->wpa.key[index].ext_flags = enc->ext_flags;
+	if (enc->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
+		priv->wpa.txkey = index;
+		commit |= SME_WEP_INDEX;
+	} else if (enc->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
+		memcpy(&priv->wpa.key[index].rx_seq[0],
+			enc->rx_seq, IW_ENCODE_SEQ_MAX_SIZE);
+	}
 
-		switch (enc->alg) {
-		case IW_ENCODE_ALG_NONE:
-			if (priv->reg.privacy_invoked) {
-				priv->reg.privacy_invoked = 0x00;
-				commit |= SME_WEP_FLAG;
-			}
-			priv->wpa.key[index].key_len = 0;
+	memcpy(&priv->wpa.key[index].addr.sa_data[0],
+		&enc->addr.sa_data[0], ETH_ALEN);
 
-			break;
-		case IW_ENCODE_ALG_WEP:
-		case IW_ENCODE_ALG_CCMP:
-			if (!priv->reg.privacy_invoked) {
-				priv->reg.privacy_invoked = 0x01;
-				commit |= SME_WEP_FLAG;
-			}
-			if (enc->key_len) {
-				memcpy(&priv->wpa.key[index].key_val[0],
-				       &enc->key[0], enc->key_len);
-				priv->wpa.key[index].key_len = enc->key_len;
-				commit |= (SME_WEP_VAL1 << index);
-			}
-			break;
-		case IW_ENCODE_ALG_TKIP:
-			if (!priv->reg.privacy_invoked) {
-				priv->reg.privacy_invoked = 0x01;
-				commit |= SME_WEP_FLAG;
-			}
-			if (enc->key_len == 32) {
-				memcpy(&priv->wpa.key[index].key_val[0],
-				       &enc->key[0], enc->key_len - 16);
-				priv->wpa.key[index].key_len =
-				    enc->key_len - 16;
-				if (priv->wpa.key_mgmt_suite == 4) {	/* WPA_NONE */
-					memcpy(&priv->wpa.key[index].
-					       tx_mic_key[0], &enc->key[16], 8);
-					memcpy(&priv->wpa.key[index].
-					       rx_mic_key[0], &enc->key[16], 8);
-				} else {
-					memcpy(&priv->wpa.key[index].
-					       tx_mic_key[0], &enc->key[16], 8);
-					memcpy(&priv->wpa.key[index].
-					       rx_mic_key[0], &enc->key[24], 8);
-				}
-				commit |= (SME_WEP_VAL1 << index);
+	switch (enc->alg) {
+	case IW_ENCODE_ALG_NONE:
+		if (priv->reg.privacy_invoked) {
+			priv->reg.privacy_invoked = 0x00;
+			commit |= SME_WEP_FLAG;
+		}
+		priv->wpa.key[index].key_len = 0;
+
+		break;
+	case IW_ENCODE_ALG_WEP:
+	case IW_ENCODE_ALG_CCMP:
+		if (!priv->reg.privacy_invoked) {
+			priv->reg.privacy_invoked = 0x01;
+			commit |= SME_WEP_FLAG;
+		}
+		if (enc->key_len) {
+			memcpy(&priv->wpa.key[index].key_val[0],
+				&enc->key[0], enc->key_len);
+			priv->wpa.key[index].key_len = enc->key_len;
+			commit |= (SME_WEP_VAL1 << index);
+		}
+		break;
+	case IW_ENCODE_ALG_TKIP:
+		if (!priv->reg.privacy_invoked) {
+			priv->reg.privacy_invoked = 0x01;
+			commit |= SME_WEP_FLAG;
+		}
+		if (enc->key_len == 32) {
+			memcpy(&priv->wpa.key[index].key_val[0],
+				&enc->key[0], enc->key_len - 16);
+			priv->wpa.key[index].key_len =
+				enc->key_len - 16;
+			if (priv->wpa.key_mgmt_suite == 4) {	/* WPA_NONE */
+				memcpy(&priv->wpa.key[index].
+					tx_mic_key[0], &enc->key[16], 8);
+				memcpy(&priv->wpa.key[index].
+					rx_mic_key[0], &enc->key[16], 8);
+			} else {
+				memcpy(&priv->wpa.key[index].
+					tx_mic_key[0], &enc->key[16], 8);
+				memcpy(&priv->wpa.key[index].
+					rx_mic_key[0], &enc->key[24], 8);
 			}
-			break;
-		default:
-			return -EINVAL;
+			commit |= (SME_WEP_VAL1 << index);
 		}
-		priv->wpa.key[index].alg = enc->alg;
-	} else {
+		break;
+	default:
 		return -EINVAL;
 	}
+	priv->wpa.key[index].alg = enc->alg;
 
 	if (commit) {
 		if (commit & SME_WEP_INDEX)
@@ -2145,51 +2144,53 @@ static int ks_wlan_set_pmksa(struct net_device *dev,
 				if (!memcmp
 				    ("\x00\x00\x00\x00\x00\x00", pmk->bssid,
 				     ETH_ALEN))
-					break;
+					break; /* loop */
 			}
 			memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
 			memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
 			list_add(&pmk->list, &priv->pmklist.head);
 			priv->pmklist.size++;
-		} else {	/* search cache data */
-			list_for_each(ptr, &priv->pmklist.head) {
-				pmk = list_entry(ptr, struct pmk_t, list);
-				if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) {	/* match address! list move to head. */
-					memcpy(pmk->pmkid, pmksa->pmkid,
-					       IW_PMKID_LEN);
-					list_move(&pmk->list,
-						  &priv->pmklist.head);
-					break;
-				}
+			break;	/* case */
+		}
+		/* search cache data */
+		list_for_each(ptr, &priv->pmklist.head) {
+			pmk = list_entry(ptr, struct pmk_t, list);
+			if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) {	/* match address! list move to head. */
+				memcpy(pmk->pmkid, pmksa->pmkid,
+					IW_PMKID_LEN);
+				list_move(&pmk->list,
+					&priv->pmklist.head);
+				break; /* list_for_each */
 			}
-			if (ptr == &priv->pmklist.head) {	/* not find address. */
-				if (priv->pmklist.size <= PMK_LIST_MAX) {	/* new cache data */
-					for (i = 0; i < PMK_LIST_MAX; i++) {
-						pmk = &priv->pmklist.pmk[i];
-						if (!memcmp
-						    ("\x00\x00\x00\x00\x00\x00",
-						     pmk->bssid, ETH_ALEN))
-							break;
-					}
-					memcpy(pmk->bssid, pmksa->bssid.sa_data,
-					       ETH_ALEN);
-					memcpy(pmk->pmkid, pmksa->pmkid,
-					       IW_PMKID_LEN);
-					list_add(&pmk->list,
-						 &priv->pmklist.head);
-					priv->pmklist.size++;
-				} else {	/* overwrite old cache data */
-					pmk =
-					    list_entry(priv->pmklist.head.prev,
-						       struct pmk_t, list);
-					memcpy(pmk->bssid, pmksa->bssid.sa_data,
-					       ETH_ALEN);
-					memcpy(pmk->pmkid, pmksa->pmkid,
-					       IW_PMKID_LEN);
-					list_move(&pmk->list,
-						  &priv->pmklist.head);
-				}
+		}
+		if (ptr != &priv->pmklist.head)	/* not find address. */
+			break;	/* case */
+
+		if (priv->pmklist.size <= PMK_LIST_MAX) {	/* new cache data */
+			for (i = 0; i < PMK_LIST_MAX; i++) {
+				pmk = &priv->pmklist.pmk[i];
+				if (!memcmp
+					("\x00\x00\x00\x00\x00\x00",
+						pmk->bssid, ETH_ALEN))
+					break;
 			}
+			memcpy(pmk->bssid, pmksa->bssid.sa_data,
+				ETH_ALEN);
+			memcpy(pmk->pmkid, pmksa->pmkid,
+				IW_PMKID_LEN);
+			list_add(&pmk->list,
+				&priv->pmklist.head);
+			priv->pmklist.size++;
+		} else {	/* overwrite old cache data */
+			pmk =
+				list_entry(priv->pmklist.head.prev,
+					struct pmk_t, list);
+			memcpy(pmk->bssid, pmksa->bssid.sa_data,
+				ETH_ALEN);
+			memcpy(pmk->pmkid, pmksa->pmkid,
+				IW_PMKID_LEN);
+			list_move(&pmk->list,
+				&priv->pmklist.head);
 		}
 		break;
 	case IW_PMKSA_REMOVE:
-- 
2.7.4

  parent reply	other threads:[~2017-03-13 22:54 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-13 22:53 [PATCH 00/12] staging: ks7010: fix checkpatch ks_wlan_net.c Tobin C. Harding
2017-03-13 22:53 ` [PATCH 01/12] staging: ks7010: fix checkpatch SPACING Tobin C. Harding
2017-03-13 22:54 ` [PATCH 02/12] staging: ks7010: fix checkpatch BLOCK_COMMENT_STYLE Tobin C. Harding
2017-03-13 22:54 ` [PATCH 03/12] staging: ks7010: convert comments to kernel doc format Tobin C. Harding
2017-03-14  0:06   ` Greg Kroah-Hartman
2017-03-14  1:39     ` Tobin C. Harding
2017-03-14  1:41       ` Greg Kroah-Hartman
2017-03-13 22:54 ` [PATCH 04/12] staging: ks7010: fix logical line continuation Tobin C. Harding
2017-03-13 22:54 ` [PATCH 05/12] staging: ks7010: remove dead code Tobin C. Harding
2017-03-13 22:54 ` [PATCH 06/12] staging: ks7010: remove multiple assignment Tobin C. Harding
2017-03-13 22:54 ` [PATCH 07/12] staging: ks7010: move comparison to right hand side Tobin C. Harding
2017-03-14  9:17   ` Dan Carpenter
2017-03-14 10:42     ` Tobin C. Harding
2017-03-13 22:54 ` [PATCH 08/12] staging: ks7010: remove unnecessary else statement Tobin C. Harding
2017-03-14  9:23   ` Dan Carpenter
2017-03-14 10:54     ` Tobin C. Harding
2017-03-14 11:18       ` Dan Carpenter
2017-03-14 20:34         ` Tobin C. Harding
2017-03-13 22:54 ` [PATCH 09/12] staging: ks7010: remove unnecessary cast Tobin C. Harding
2017-03-14  0:07   ` Greg Kroah-Hartman
2017-03-14  1:41     ` Tobin C. Harding
2017-03-13 22:54 ` [PATCH 10/12] staging: ks7010: fix checkpatch memset warning Tobin C. Harding
2017-03-14  9:27   ` Dan Carpenter
2017-03-14 10:44     ` Tobin C. Harding
2017-03-14 11:08       ` Dan Carpenter
2017-03-13 22:54 ` Tobin C. Harding [this message]
2017-03-13 22:54 ` [PATCH 12/12] staging: ks7010: refactor, whitespace only Tobin C. Harding

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1489445650-11398-12-git-send-email-me@tobin.cc \
    --to=me@tobin.cc \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=wsa@the-dreams.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.