Skip to contentSkip to conversation

staging: rtl8192u: Remove ternary operator

PATCH Superseded Gargi Sharma 3 participants 4 messages Feb 20, 2017 – Feb 26, 2017 Staging

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 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. In a few cases using logical && operator would suffice. Hence those were changed 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 v4:
- Aligned operands for && and added a newline.
Changes in v3:
- Converted ? operator to &&.
Changes in v2:
- Converted ? operator to if else statements.

---

---
 drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c +9 -8
index c27397b..b17bdf9 100644
@@ -977,16 +977,18 @@ 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);
+
+	pHTInfo->bCurTxBW40MHz = (pPeerHTInfo->RecommemdedTxWidth == 1);
 
 	//
 	// 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);
+	pHTInfo->bCurShortGI20MHz = pHTInfo->bRegShortGI20MHz &&
+				    (pPeerHTCap->ShortGI20Mhz == 1);
+
+	pHTInfo->bCurShortGI40MHz = pHTInfo->bRegShortGI40MHz &&
+				    (pPeerHTCap->ShortGI40Mhz == 1);
 
 	//
 	// Config TX STBC setting
@@ -997,9 +999,8 @@ void HTOnAssocRsp(struct ieee80211_device *ieee)
 	// Config DSSS/CCK  mode in 40MHz mode
 	//
 	// TODO:
-	pHTInfo->bCurSuppCCK =
-		((pHTInfo->bRegSuppCCK)?((pPeerHTCap->DssCCk==1)?true:false):false);
-
+	pHTInfo->bCurSuppCCK = pHTInfo->bRegSuppCCK &&
+			       (pPeerHTCap->DssCCk == 1);
 
 	//
 	// Config and configure A-MSDU setting
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 33 lines · Gargi Sharma

Relational and logical operators evaluate to either true or false. Lines with ternary operators were found using coccinelle script. In a few cases using logical && operator would suffice. Hence those were changed 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 v4:
- Aligned operands for && and added a newline.
Changes in v3:
- Converted ? operator to &&.
Changes in v2:
- Converted ? operator to if else statements.

---

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

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

Quoted 6 lines
drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c +2 -1
@@ -977,16 +977,18 @@ 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);
+
+	pHTInfo->bCurTxBW40MHz = (pPeerHTInfo->RecommemdedTxWidth == 1);

While the indentation does make sense, it does not look correct with the if statement still there, right? Please fix this up when you resend this.

thanks,

greg k-h

#2 lore raw
Quoted 25 lines · Greg KH
Quoted 23 lines · Gargi Sharma

Relational and logical operators evaluate to either true or false. Lines with ternary operators were found using coccinelle script. In a few cases using logical && operator would suffice. Hence those were changed 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 v4:
- Aligned operands for && and added a newline.
Changes in v3:
- Converted ? operator to &&.
Changes in v2:
- Converted ? operator to if else statements.

Quoted 3 lines
Quoted 3 lines

---

---
 drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c | 17

+++++++++--------

Quoted 3 lines

Review

Quoted 3 lines
 1 file changed, 9 insertions(+), 8 deletions(-)
(quoted diff) +0 -0

b/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c

Quoted 5 lines

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

Quoted 5 lines

index c27397b..b17bdf9 100644

drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c +0 -0
@@ -977,16 +977,18 @@ void HTOnAssocRsp(struct ieee80211_device *ieee)
      HTSetConnectBwMode(ieee, (HT_CHANNEL_WIDTH)(pPeerHTCap->ChlWidth),

(HT_EXTCHNL_OFFSET)(pPeerHTInfo->ExtChlOffset));

Quoted 1 line
Quoted 1 line

if (pHTInfo->bCurBW40MHz)
Is this the if statement you are talking about? Should I remove this or fix the alignment for the next statement?

Thanks,
Gargi

Quoted 1 line
Quoted 1 line

- pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth

== 1)?true:false);

Quoted 10 lines

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

Quoted 2 lines
drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c +2 -0
+
+     pHTInfo->bCurTxBW40MHz = (pPeerHTInfo->RecommemdedTxWidth == 1);

While the indentation does make sense, it does not look correct with the if statement still there, right? Please fix this up when you resend this.

thanks,

greg k-h

#3 lore raw
Quoted 41 lines · Gargi Sharma
Quoted 25 lines · Greg KH
Quoted 23 lines · Gargi Sharma

Relational and logical operators evaluate to either true or false. Lines with ternary operators were found using coccinelle script. In a few cases using logical && operator would suffice. Hence those were changed 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 v4:
        - Aligned operands for && and added a newline. Changes in v3:
        - Converted ? operator to &&.
Changes in v2:
        - Converted ? operator to if else statements.

Quoted 3 lines
Quoted 3 lines

---
---
 drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c | 17

+++++++++--------

Quoted 3 lines

Review

Quoted 3 lines
 1 file changed, 9 insertions(+), 8 deletions(-)
(quoted diff) +0 -0

b/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c

Quoted 5 lines

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

Quoted 5 lines

index c27397b..b17bdf9 100644

drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c +0 -0
@@ -977,16 +977,18 @@ void HTOnAssocRsp(struct ieee80211_device *ieee)
       HTSetConnectBwMode(ieee, (HT_CHANNEL_WIDTH)(pPeerHTCap->ChlWidth),

(HT_EXTCHNL_OFFSET)(pPeerHTInfo->ExtChlOffset));

Quoted 10 lines
Quoted 1 line
Quoted 1 line

if (pHTInfo->bCurBW40MHz)Is this the if statement you are talking about?

Should I remove this or fix the alignment for the next statement?

Thanks,
Gargi

Quoted 1 line
Quoted 1 line

-             pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth

== 1)?true:false);

Quoted 2 lines
Quoted 2 lines

+
+     pHTInfo->bCurTxBW40MHz = (pPeerHTInfo->RecommemdedTxWidth == 1);

The code just above was originally below an if that was preceeded by a //. Ad you can see just above, you reduced the indentation, to reflect that the code is not really under an if any more. Greg thought it looked odd. You can just get rid of the if under //. In general, the policy in the Linux kernel is that there should not be code under comments. It should just be removed.

julia

Quoted 20 lines
Quoted 8 lines

While the indentation does make sense, it does not look correct with the if statement still there, right?  Please fix this up when you resend this.

thanks,

greg k-h

--
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 visithttps://groups.google.com/d/msgid/outreachy-kernel/CAOCi2DE6hbgroFNfo5P8hDx gMxk2JCez1zADarnZVCL2uJrCCw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.