Skip to contentSkip to conversation

staging: rtl8192u: Remove ternary operator

PATCH Superseded Gargi Sharma 2 participants 2 messages Feb 19, 2017 Staging

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 staging: rtl8192u: Remove ternary operator

Relational and logical operators evaluate to either true or false. Lines with ternary operators were found using coccinelle script and conversion to if else statements was done manually to improve readability.

Coccinelle Script:
@r@
expression A,B;
symbol true,false;
binary operator b = {==,!=,&&,||,>=,<=,>,<};
@@
- (A b B) ? true : false
+ A b B

---
Changes in v2:
- Converted ? operator to if else statements.

---
 .../staging/rtl8192u/ieee80211/rtl819x_HTProc.c    | 24 +++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c +17 -7
index c27397b..cc4394e 100644
@@ -977,16 +977,24 @@ void HTOnAssocRsp(struct ieee80211_device *ieee)
 	HTSetConnectBwMode(ieee, (HT_CHANNEL_WIDTH)(pPeerHTCap->ChlWidth), (HT_EXTCHNL_OFFSET)(pPeerHTInfo->ExtChlOffset));
 
 //	if (pHTInfo->bCurBW40MHz)
-		pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth == 1)?true:false);
+	if (pPeerHTInfo->RecommemdedTxWidth == 1)
+		pHTInfo->bCurTxBW40MHz = true;
+	else
+		pHTInfo->bCurTxBW40MHz = false;
 
 	//
 	// Update short GI/ long GI setting
 	//
 	// TODO:
-	pHTInfo->bCurShortGI20MHz=
-		((pHTInfo->bRegShortGI20MHz)?((pPeerHTCap->ShortGI20Mhz==1)?true:false):false);
-	pHTInfo->bCurShortGI40MHz=
-		((pHTInfo->bRegShortGI40MHz)?((pPeerHTCap->ShortGI40Mhz==1)?true:false):false);
+	if (pHTInfo->bRegShortGI20MHz == 1)
+		pHTInfo->bCurShortGI20MHz = (pPeerHTCap->ShortGI20Mhz == 1);
+	else
+		pHTInfo->bCurShortGI20MHz = false;
+
+	if (pHTInfo->bRegShortGI40MHz == 1)
+		pHTInfo->bCurShortGI40MHz = (pPeerHTCap->ShortGI40Mhz == 1);
+	else
+		pHTInfo->bCurShortGI40MHz = false;
 
 	//
 	// Config TX STBC setting
@@ -997,9 +1005,11 @@ void HTOnAssocRsp(struct ieee80211_device *ieee)
 	// Config DSSS/CCK  mode in 40MHz mode
 	//
 	// TODO:
-	pHTInfo->bCurSuppCCK =
-		((pHTInfo->bRegSuppCCK)?((pPeerHTCap->DssCCk==1)?true:false):false);
 
+	if (pHTInfo->bRegSuppCCK == 1)
+		pHTInfo->bCurSuppCCK = (pPeerHTCap->DssCCk == 1);
+	else
+		pHTInfo->bCurSuppCCK = false;
 
 	//
 	// Config and configure A-MSDU setting
Signature · 1 line
2.7.4
#1 lore raw
Quoted 27 lines · Gargi Sharma

Relational and logical operators evaluate to either true or false. Lines with ternary operators were found using coccinelle script and conversion to if else statements was done manually to improve readability.

Coccinelle Script:
@r@
expression A,B;
symbol true,false;
binary operator b = {==,!=,&&,||,>=,<=,>,<};
@@
- (A b B) ? true : false
+ A b B

---
Changes in v2:
- Converted ? operator to if else statements.

---
 .../staging/rtl8192u/ieee80211/rtl819x_HTProc.c    | 24 +++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c +0 -0
index c27397b..cc4394e 100644

drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c void HTOnAssocRsp(struct ieee80211_device *ieee) · line 983

Quoted 8 lines
drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c +4 -1
@@ -977,16 +977,24 @@ void HTOnAssocRsp(struct ieee80211_device *ieee)
 	HTSetConnectBwMode(ieee, (HT_CHANNEL_WIDTH)(pPeerHTCap->ChlWidth), (HT_EXTCHNL_OFFSET)(pPeerHTInfo->ExtChlOffset));
 
 //	if (pHTInfo->bCurBW40MHz)
-		pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth == 1)?true:false);
+	if (pPeerHTInfo->RecommemdedTxWidth == 1)
+		pHTInfo->bCurTxBW40MHz = true;
+	else
+		pHTInfo->bCurTxBW40MHz = false;

Sorry, I wasn't suggesting tochange this one to an if. You were already able to completely get rid of the ?

Quoted 8 lines
drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c +0 -3
 	//
 	// Update short GI/ long GI setting
 	//
 	// TODO:
-	pHTInfo->bCurShortGI20MHz=
-		((pHTInfo->bRegShortGI20MHz)?((pPeerHTCap->ShortGI20Mhz==1)?true:false):false);
-	pHTInfo->bCurShortGI40MHz=

drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c void HTOnAssocRsp(struct ieee80211_device *ieee) · line 997

Quoted 10 lines
drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c +9 -1
-		((pHTInfo->bRegShortGI40MHz)?((pPeerHTCap->ShortGI40Mhz==1)?true:false):false);
+	if (pHTInfo->bRegShortGI20MHz == 1)
+		pHTInfo->bCurShortGI20MHz = (pPeerHTCap->ShortGI20Mhz == 1);
+	else
+		pHTInfo->bCurShortGI20MHz = false;
+
+	if (pHTInfo->bRegShortGI40MHz == 1)
+		pHTInfo->bCurShortGI40MHz = (pPeerHTCap->ShortGI40Mhz == 1);
+	else
+		pHTInfo->bCurShortGI40MHz = false;

Now that the code is more readable, it seems that actually the if is not needed, and you can use &&. The same for the next one.

julia

Quoted 26 lines
drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c +4 -3
 	//
 	// Config TX STBC setting
@@ -997,9 +1005,11 @@ void HTOnAssocRsp(struct ieee80211_device *ieee)
 	// Config DSSS/CCK  mode in 40MHz mode
 	//
 	// TODO:
-	pHTInfo->bCurSuppCCK =
-		((pHTInfo->bRegSuppCCK)?((pPeerHTCap->DssCCk==1)?true:false):false);
 
+	if (pHTInfo->bRegSuppCCK == 1)
+		pHTInfo->bCurSuppCCK = (pPeerHTCap->DssCCk == 1);
+	else
+		pHTInfo->bCurSuppCCK = false;
 
 	//
 	// Config and configure A-MSDU setting
--

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/1487535589-22437-1-git-send-email-gs051095%40gmail.com.
For more options, visit https://groups.google.com/d/optout.