Skip to contentSkip to conversation

staging: rtl8192u: ieee80211: Move assignment out of the if.

PATCH In review Elise Lennion 2 participants 2 messages Oct 19, 2016 – Oct 20, 2016 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rtl8192u: ieee80211: Move assignment out of the if.

Assignments inside of if statements confuse the reader and should be avoided, so it was moved out before the if.

Found with Coccinelle, semantic patch:
@@
expression e1, e2;
statement S;
position p;
@@

+ e1 = e2;
if (<+...
- (e1 = e2)
@p
+ e1
...+>)
S

---
 drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +2 -2
index 89cbc07..0d81b3a 100644
@@ -1145,8 +1145,8 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
 
 	/* skb: hdr + (possibly fragmented, possibly encrypted) payload */
 
-	if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
-	    (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
+	keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt);
+	if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) && keyidx < 0)
 	{
 		printk("decrypt frame error\n");
 		goto rx_dropped;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 28 lines · Elise Lennion

Assignments inside of if statements confuse the reader and should be avoided, so it was moved out before the if.

Found with Coccinelle, semantic patch:
@@
expression e1, e2;
statement S;
position p;
@@

+ e1 = e2;
if (<+...
- (e1 = e2)
@p
+ e1
...+>)
S

---
 drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +0 -0
index 89cbc07..0d81b3a 100644

drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb, · line 1149

Quoted 7 lines
drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +2 -2
@@ -1145,8 +1145,8 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
 
 	/* skb: hdr + (possibly fragmented, possibly encrypted) payload */
 
-	if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
-	    (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
+	keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt);
+	if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) && keyidx < 0)

Yeah, this is indeed not a good idea.

julia

Quoted 13 lines
drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +0 -1
 	{
 		printk("decrypt frame error\n");
 		goto rx_dropped;
--

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/20161019215641.GA309%40lennorien.com.
For more options, visit https://groups.google.com/d/optout.