Skip to contentSkip to conversation

staging: wilc1000: merge 'if' statements that test the same condition

PATCH In review Dafna Hirschfeld 2 participants 2 messages Feb 24, 2018 Staging

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 staging: wilc1000: merge 'if' statements that test the same condition

Merge the instructions of two 'if' statements that test the same condition and move a 'memcpy' instruction related to a different variable. Issue found with coccicheck.

---

Changes in v2:
Grouping instructions that relate to the same variables.

 drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +3 -7
index 621810d..557ab99 100644
@@ -959,18 +959,14 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
 				}
 
 				kfree(priv->wilc_ptk[key_index]->key);
-
 				priv->wilc_ptk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
+				memcpy(priv->wilc_ptk[key_index]->key, params->key, params->key_len);
 
 				kfree(priv->wilc_ptk[key_index]->seq);
-
-				if (params->seq_len > 0)
+				if (params->seq_len > 0) {
 					priv->wilc_ptk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
-
-				memcpy(priv->wilc_ptk[key_index]->key, params->key, params->key_len);
-
-				if (params->seq_len > 0)
 					memcpy(priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len);
+				}
 
 				priv->wilc_ptk[key_index]->cipher = params->cipher;
 				priv->wilc_ptk[key_index]->key_len = params->key_len;
Signature · 1 line
2.7.4
Acked-by on v2 1/1
#1 lore raw
Quoted 5 lines · Dafna Hirschfeld

Merge the instructions of two 'if' statements that test the same condition and move a 'memcpy' instruction related to a different variable. Issue found with coccicheck.

OK, on a wide screen, the code looks nice...

This code is under an if, that is pushing it off to the right. But just below there is another sequences of lines of code that is in a { } for no reason at all. Perhaps that could be removed, moving all the code in the block left by one tab space.

julia

Quoted 44 lines

---

Changes in v2:
Grouping instructions that relate to the same variables.

 drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +3 -8
index 621810d..557ab99 100644
@@ -959,18 +959,14 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
 				}
 
 				kfree(priv->wilc_ptk[key_index]->key);
-
 				priv->wilc_ptk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
+				memcpy(priv->wilc_ptk[key_index]->key, params->key, params->key_len);
 
 				kfree(priv->wilc_ptk[key_index]->seq);
-
-				if (params->seq_len > 0)
+				if (params->seq_len > 0) {
 					priv->wilc_ptk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
-
-				memcpy(priv->wilc_ptk[key_index]->key, params->key, params->key_len);
-
-				if (params->seq_len > 0)
 					memcpy(priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len);
+				}
 
 				priv->wilc_ptk[key_index]->cipher = params->cipher;
 				priv->wilc_ptk[key_index]->key_len = params->key_len;
--

2.7.4

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20180224102722.GA11743%40gmail.com.
For more options, visit https://groups.google.com/d/optout.