Skip to contentSkip to conversation

staging: rtl8192e: rtllib_crypt_tkip: code cleanup on rtllib_crypt_tkip.c

PATCH In review Aaron Lawrence 2 participants 8 messages Oct 26, 2022 Staging

lore
Share & tools
lore
#0 lore raw

cover staging: rtl8192e: rtllib_crypt_tkip: code cleanup on rtllib_crypt_tkip.c

Multiple patches regarding the cleanup of code in rtllib_crypt_tkip.c. Fixes were applied according to the reports generated by running the checkpatch script on said file with minor manual adjustments by personal judgement with handling the comments on the multiple assignments issue.

Aaron Lawrence (6):
staging: rtl8192e: rtllib_crypt_tkip: multiple blank lines removal
staging: rtl8192e: rtllib_crypt_tkip: blank line before close brace
removal
staging: rtl8192e: rtllib_crypt_tkip: fixed alignment matching open
parentheses
staging: rtl8192e: rtllib_crypt_tkip: fixes on unbalanced braces
staging: rtl8192e: rtllib_crypt_tkip: split multiple assignments
staging: rtl8192e: rtllib_crypt_tkip: rewritten comparison to NULL

 drivers/staging/rtl8192e/rtllib_crypt_tkip.c | 52 ++++++--------------
 1 file changed, 16 insertions(+), 36 deletions(-)
Signature · 1 line
2.38.1
#1 lore raw

PATCH 1/6 staging: rtl8192e: rtllib_crypt_tkip: multiple blank lines removal

Removed multiple unnecessary blank lines in accordance with the Linux kernel coding-style regulations. The issues were reported by the checkpatch script.

---
 drivers/staging/rtl8192e/rtllib_crypt_tkip.c | 24 --------------------
 1 file changed, 24 deletions(-)
drivers/staging/rtl8192e/rtllib_crypt_tkip.c +0 -24
index 8bc95651e384..468f28f48eba 100644
@@ -91,7 +91,6 @@ static void *rtllib_tkip_init(int key_idx)
 	return NULL;
 }
 
-
 static void rtllib_tkip_deinit(void *priv)
 {
 	struct rtllib_tkip_data *_priv = priv;
@@ -103,49 +102,41 @@ static void rtllib_tkip_deinit(void *priv)
 	kfree_sensitive(priv);
 }
 
-
 static inline u16 RotR1(u16 val)
 {
 	return (val >> 1) | (val << 15);
 }
 
-
 static inline u8 Lo8(u16 val)
 {
 	return val & 0xff;
 }
 
-
 static inline u8 Hi8(u16 val)
 {
 	return val >> 8;
 }
 
-
 static inline u16 Lo16(u32 val)
 {
 	return val & 0xffff;
 }
 
-
 static inline u16 Hi16(u32 val)
 {
 	return val >> 16;
 }
 
-
 static inline u16 Mk16(u8 hi, u8 lo)
 {
 	return lo | (hi << 8);
 }
 
-
 static inline u16 Mk16_le(u16 *v)
 {
 	return *v;
 }
 
-
 static const u16 Sbox[256] = {
 	0xC6A5, 0xF884, 0xEE99, 0xF68D, 0xFF0D, 0xD6BD, 0xDEB1, 0x9154,
 	0x6050, 0x0203, 0xCEA9, 0x567D, 0xE719, 0xB562, 0x4DE6, 0xEC9A,
@@ -181,17 +172,14 @@ static const u16 Sbox[256] = {
 	0x82C3, 0x29B0, 0x5A77, 0x1E11, 0x7BCB, 0xA8FC, 0x6DD6, 0x2C3A,
 };
 
-
 static inline u16 _S_(u16 v)
 {
 	u16 t = Sbox[Hi8(v)];
 	return Sbox[Lo8(v)] ^ ((t << 8) | (t >> 8));
 }
 
-
 #define PHASE1_LOOP_COUNT 8
 
-
 static void tkip_mixing_phase1(u16 *TTAK, const u8 *TK, const u8 *TA, u32 IV32)
 {
 	int i, j;
@@ -213,7 +201,6 @@ static void tkip_mixing_phase1(u16 *TTAK, const u8 *TK, const u8 *TA, u32 IV32)
 	}
 }
 
-
 static void tkip_mixing_phase2(u8 *WEPSeed, const u8 *TK, const u16 *TTAK,
 			       u16 IV16)
 {
@@ -263,7 +250,6 @@ static void tkip_mixing_phase2(u8 *WEPSeed, const u8 *TK, const u16 *TTAK,
 #endif
 }
 
-
 static int rtllib_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
 {
 	struct rtllib_tkip_data *tkey = priv;
@@ -293,7 +279,6 @@ static int rtllib_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
 	} else
 		tkey->tx_phase1_done = 1;
 
-
 	len = skb->len - hdr_len;
 	pos = skb_push(skb, 8);
 	memmove(pos, pos + 8, hdr_len);
@@ -337,7 +322,6 @@ static int rtllib_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
 		return ret;
 	return 0;
 
-
 }
 
 static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
@@ -453,7 +437,6 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 	return keyidx;
 }
 
-
 static int michael_mic(struct crypto_shash *tfm_michael, u8 *key, u8 *hdr,
 		       u8 *data, size_t data_len, u8 *mic)
 {
@@ -511,7 +494,6 @@ static void michael_mic_hdr(struct sk_buff *skb, u8 *hdr)
 	hdr[13] = hdr[14] = hdr[15] = 0; /* reserved */
 }
 
-
 static int rtllib_michael_mic_add(struct sk_buff *skb, int hdr_len, void *priv)
 {
 	struct rtllib_tkip_data *tkey = priv;
@@ -539,7 +521,6 @@ static int rtllib_michael_mic_add(struct sk_buff *skb, int hdr_len, void *priv)
 	return 0;
 }
 
-
 static void rtllib_michael_mic_failure(struct net_device *dev,
 				       struct rtllib_hdr_4addr *hdr,
 				       int keyidx)
@@ -609,7 +590,6 @@ static int rtllib_michael_mic_verify(struct sk_buff *skb, int keyidx,
 	return 0;
 }
 
-
 static int rtllib_tkip_set_key(void *key, int len, u8 *seq, void *priv)
 {
 	struct rtllib_tkip_data *tkey = priv;
@@ -640,7 +620,6 @@ static int rtllib_tkip_set_key(void *key, int len, u8 *seq, void *priv)
 	return 0;
 }
 
-
 static int rtllib_tkip_get_key(void *key, int len, u8 *seq, void *priv)
 {
 	struct rtllib_tkip_data *tkey = priv;
@@ -671,7 +650,6 @@ static int rtllib_tkip_get_key(void *key, int len, u8 *seq, void *priv)
 	return TKIP_KEY_LEN;
 }
 
-
 static void rtllib_tkip_print_stats(struct seq_file *m, void *priv)
 {
 	struct rtllib_tkip_data *tkip = priv;
@@ -713,13 +691,11 @@ static struct lib80211_crypto_ops rtllib_crypt_tkip = {
 	.owner			= THIS_MODULE,
 };
 
-
 static int __init rtllib_crypto_tkip_init(void)
 {
 	return lib80211_register_crypto_ops(&rtllib_crypt_tkip);
 }
 
-
 static void __exit rtllib_crypto_tkip_exit(void)
 {
 	lib80211_unregister_crypto_ops(&rtllib_crypt_tkip);
Signature · 1 line
2.38.1
#2 lore raw

PATCH 2/6 staging: rtl8192e: rtllib_crypt_tkip: blank line before close brace removal

In reply to Aaron Lawrence

Removed multiple blank lines that are not necessary before a closing brace. The issues were found with the checkpatch script and were dealt with in accordance with the Linux kernel coding-style guidelines.

---
 drivers/staging/rtl8192e/rtllib_crypt_tkip.c | 2 --
 1 file changed, 2 deletions(-)
drivers/staging/rtl8192e/rtllib_crypt_tkip.c +0 -2
index 468f28f48eba..40930c9b0017 100644
@@ -321,7 +321,6 @@ static int rtllib_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
 	if (!tcb_desc->bHwSec)
 		return ret;
 	return 0;
-
 }
 
 static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
@@ -420,7 +419,6 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 			tkey->dot11RSNAStatsTKIPICVErrors++;
 			return -5;
 		}
-
 	}
 
 	/* Update real counters only after Michael MIC verification has
Signature · 1 line
2.38.1
#3 lore raw

PATCH 3/6 staging: rtl8192e: rtllib_crypt_tkip: fixed alignment matching open parentheses

In reply to Aaron Lawrence

Aligned multiple lines to be at the same indentation of open parentheses before it in accordance with the Linux kernel coding-style regulations. The issues were found by running the checkpatch script on the file.

---
 drivers/staging/rtl8192e/rtllib_crypt_tkip.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/rtl8192e/rtllib_crypt_tkip.c +4 -4
index 40930c9b0017..6c98f43f967e 100644
@@ -271,7 +271,7 @@ static int rtllib_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
 	if (!tcb_desc->bHwSec) {
 		if (!tkey->tx_phase1_done) {
 			tkip_mixing_phase1(tkey->tx_ttak, tkey->key, hdr->addr2,
-					tkey->tx_iv32);
+					   tkey->tx_iv32);
 			tkey->tx_phase1_done = 1;
 		}
 		tkip_mixing_phase2(rc4key, tkey->key, tkey->tx_ttak,
@@ -372,8 +372,8 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 
 	if (!tcb_desc->bHwSec || (skb->cb[0] == 1)) {
 		if ((iv32 < tkey->rx_iv32 ||
-		    (iv32 == tkey->rx_iv32 && iv16 <= tkey->rx_iv16)) &&
-		    tkey->initialized) {
+		     (iv32 == tkey->rx_iv32 && iv16 <= tkey->rx_iv16)) &&
+		     tkey->initialized) {
 			if (net_ratelimit()) {
 				netdev_dbg(skb->dev,
 					   "Replay detected: STA= %pM previous TSC %08x%04x received TSC %08x%04x\n",
@@ -513,7 +513,7 @@ static int rtllib_michael_mic_add(struct sk_buff *skb, int hdr_len, void *priv)
 		tkey->tx_hdr[12] = *(skb->data + hdr_len - 2) & 0x07;
 	pos = skb_put(skb, 8);
 	if (michael_mic(tkey->tx_tfm_michael, &tkey->key[16], tkey->tx_hdr,
-	    skb->data + hdr_len, skb->len - 8 - hdr_len, pos))
+			skb->data + hdr_len, skb->len - 8 - hdr_len, pos))
 		return -1;
 
 	return 0;
Signature · 1 line
2.38.1
#4 lore raw

PATCH 4/6 staging: rtl8192e: rtllib_crypt_tkip: fixes on unbalanced braces

In reply to Aaron Lawrence

Added braces around needed arms of statements which needs them in accordance with the Linux kernel coding-style regulations. The issues were found with the help of the checkpatch script.

---
 drivers/staging/rtl8192e/rtllib_crypt_tkip.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/staging/rtl8192e/rtllib_crypt_tkip.c +5 -3
index 6c98f43f967e..d1b86de76eb2 100644
@@ -276,8 +276,9 @@ static int rtllib_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
 		}
 		tkip_mixing_phase2(rc4key, tkey->key, tkey->tx_ttak,
 				   tkey->tx_iv16);
-	} else
+	} else {
 		tkey->tx_phase1_done = 1;
+	}
 
 	len = skb->len - hdr_len;
 	pos = skb_push(skb, 8);
@@ -610,10 +611,11 @@ static int rtllib_tkip_set_key(void *key, int len, u8 *seq, void *priv)
 				(seq[3] << 8) | seq[2];
 			tkey->rx_iv16 = (seq[1] << 8) | seq[0];
 		}
-	} else if (len == 0)
+	} else if (len == 0) {
 		tkey->key_set = 0;
-	else
+	} else {
 		return -1;
+	}
 
 	return 0;
 }
Signature · 1 line
2.38.1
#5 lore raw

PATCH 5/6 staging: rtl8192e: rtllib_crypt_tkip: split multiple assignments

In reply to Aaron Lawrence

Split a multiple assignments statement to individual assignments on different lines in accordance with the Linux kernel coding-style regulations. Also repositioned comments on it and the statement before for increased legibility. The multiple assignments issue was found by the checkpatch script, with the comments legibility issue were through direct observation.

---
 drivers/staging/rtl8192e/rtllib_crypt_tkip.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/staging/rtl8192e/rtllib_crypt_tkip.c +6 -2
index d1b86de76eb2..b8a52b9f9d07 100644
@@ -488,9 +488,13 @@ static void michael_mic_hdr(struct sk_buff *skb, u8 *hdr)
 		break;
 	}
 
-	hdr[12] = 0; /* priority */
+	/* priority */
+	hdr[12] = 0;
 
-	hdr[13] = hdr[14] = hdr[15] = 0; /* reserved */
+	/* reserved */
+	hdr[13] = 0;
+	hdr[14] = 0;
+	hdr[15] = 0;
 }
 
 static int rtllib_michael_mic_add(struct sk_buff *skb, int hdr_len, void *priv)
Signature · 1 line
2.38.1
#6 lore raw

PATCH 6/6 staging: rtl8192e: rtllib_crypt_tkip: rewritten comparison to NULL

In reply to Aaron Lawrence

Rewritten a comparison to NULL with a negation operator in accordance with the Linux kernel coding-style regulations. The fix was directly recommended by the checkpatch script.

---
 drivers/staging/rtl8192e/rtllib_crypt_tkip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8192e/rtllib_crypt_tkip.c +1 -1
index b8a52b9f9d07..9fdfcc017ee6 100644
@@ -62,7 +62,7 @@ static void *rtllib_tkip_init(int key_idx)
 		return NULL;
 
 	priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
-	if (priv == NULL)
+	if (!priv)
 		goto fail;
 	priv->key_idx = key_idx;
 
Signature · 1 line
2.38.1
Tested-by on the v1 series
#7 lore raw
In reply to Aaron Lawrence
Quoted 15 lines · Aaron Lawrence

Multiple patches regarding the cleanup of code in rtllib_crypt_tkip.c. Fixes were applied according to the reports generated by running the checkpatch script on said file with minor manual adjustments by personal judgement with handling the comments on the multiple assignments issue.

Aaron Lawrence (6):
staging: rtl8192e: rtllib_crypt_tkip: multiple blank lines removal
staging: rtl8192e: rtllib_crypt_tkip: blank line before close brace
removal
staging: rtl8192e: rtllib_crypt_tkip: fixed alignment matching open
parentheses
staging: rtl8192e: rtllib_crypt_tkip: fixes on unbalanced braces
staging: rtl8192e: rtllib_crypt_tkip: split multiple assignments
staging: rtl8192e: rtllib_crypt_tkip: rewritten comparison to NULL

Quoted 3 lines
  drivers/staging/rtl8192e/rtllib_crypt_tkip.c | 52 ++++++--------------
  1 file changed, 16 insertions(+), 36 deletions(-)