Skip to contentSkip to conversation

Staging: rtl8192e: Remove ternary operator

PATCH In review Bhumika Goyal 3 participants 8 messages Oct 8, 2016 – Oct 9, 2016 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: rtl8192e: Remove ternary operator

Relational and logical operators evaluate to either true or false. Explicit conversion is not needed so remove the ternary operator. Done using coccinelle:

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

---
 drivers/staging/rtl8192e/rtl819x_HTProc.c | 12 ++++--------
 drivers/staging/rtl8192e/rtllib.h         |  2 +-
 2 files changed, 5 insertions(+), 9 deletions(-)
drivers/staging/rtl8192e/rtl819x_HTProc.c +4 -8
index dd9c0c8..8cd51a9 100644
@@ -558,19 +558,15 @@ void HTOnAssocRsp(struct rtllib_device *ieee)
 #endif
 	HTSetConnectBwMode(ieee, (enum ht_channel_width)(pPeerHTCap->ChlWidth),
 			  (enum ht_extchnl_offset)(pPeerHTInfo->ExtChlOffset));
-	pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth == 1) ?
-				 true : false);
+	pHTInfo->bCurTxBW40MHz = (pPeerHTInfo->RecommemdedTxWidth == 1);
 
 	pHTInfo->bCurShortGI20MHz = ((pHTInfo->bRegShortGI20MHz) ?
-				    ((pPeerHTCap->ShortGI20Mhz == 1) ?
-				    true : false) : false);
+				    (pPeerHTCap->ShortGI20Mhz == 1) : false);
 	pHTInfo->bCurShortGI40MHz = ((pHTInfo->bRegShortGI40MHz) ?
-				     ((pPeerHTCap->ShortGI40Mhz == 1) ?
-				     true : false) : false);
+				     (pPeerHTCap->ShortGI40Mhz == 1) : false);
 
 	pHTInfo->bCurSuppCCK = ((pHTInfo->bRegSuppCCK) ?
-			       ((pPeerHTCap->DssCCk == 1) ? true :
-			       false) : false);
+			       (pPeerHTCap->DssCCk == 1) : false);
 
 
 	pHTInfo->bCurrent_AMSDU_Support = pHTInfo->bAMSDU_Support;
drivers/staging/rtl8192e/rtllib.h +1 -1
index b895a53..f2c28f3 100644
@@ -464,7 +464,7 @@ struct ieee_param {
 #define RTLLIB_QCTL_TID	      0x000F
 
 #define	FC_QOS_BIT					BIT7
-#define IsDataFrame(pdu)	(((pdu[0] & 0x0C) == 0x08) ? true : false)
+#define IsDataFrame(pdu)	((pdu[0] & 0x0C) == 0x08)
 #define	IsLegacyDataFrame(pdu)	(IsDataFrame(pdu) && (!(pdu[0]&FC_QOS_BIT)))
 #define IsQoSDataFrame(pframe)			\
 	((*(u16 *)pframe&(RTLLIB_STYPE_QOS_DATA|RTLLIB_FTYPE_DATA)) ==	\
Signature · 1 line
1.9.1
#1 lore raw
Quoted 33 lines · Bhumika Goyal

Relational and logical operators evaluate to either true or false. Explicit conversion is not needed so remove the ternary operator. Done using coccinelle:

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

---
 drivers/staging/rtl8192e/rtl819x_HTProc.c | 12 ++++--------
 drivers/staging/rtl8192e/rtllib.h         |  2 +-
 2 files changed, 5 insertions(+), 9 deletions(-)
drivers/staging/rtl8192e/rtl819x_HTProc.c +1 -4
index dd9c0c8..8cd51a9 100644
@@ -558,19 +558,15 @@ void HTOnAssocRsp(struct rtllib_device *ieee)
 #endif
 	HTSetConnectBwMode(ieee, (enum ht_channel_width)(pPeerHTCap->ChlWidth),
 			  (enum ht_extchnl_offset)(pPeerHTInfo->ExtChlOffset));
-	pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth == 1) ?
-				 true : false);
+	pHTInfo->bCurTxBW40MHz = (pPeerHTInfo->RecommemdedTxWidth == 1);
 
 	pHTInfo->bCurShortGI20MHz = ((pHTInfo->bRegShortGI20MHz) ?
-				    ((pPeerHTCap->ShortGI20Mhz == 1) ?
-				    true : false) : false);

drivers/staging/rtl8192e/rtl819x_HTProc.c void HTOnAssocRsp(struct rtllib_device *ieee) · line 569

Quoted 10 lines
drivers/staging/rtl8192e/rtl819x_HTProc.c +3 -4
+				    (pPeerHTCap->ShortGI20Mhz == 1) : false);
 	pHTInfo->bCurShortGI40MHz = ((pHTInfo->bRegShortGI40MHz) ?
-				     ((pPeerHTCap->ShortGI40Mhz == 1) ?
-				     true : false) : false);
+				     (pPeerHTCap->ShortGI40Mhz == 1) : false);
 
 	pHTInfo->bCurSuppCCK = ((pHTInfo->bRegSuppCCK) ?
-			       ((pPeerHTCap->DssCCk == 1) ? true :
-			       false) : false);
+			       (pPeerHTCap->DssCCk == 1) : false);

Even with the simplification, these look like a mess. Could && and || be used here?

julia

Quoted 26 lines
drivers/staging/rtl8192e/rtl819x_HTProc.c +0 -0
 	pHTInfo->bCurrent_AMSDU_Support = pHTInfo->bAMSDU_Support;
drivers/staging/rtl8192e/rtllib.h +1 -2
index b895a53..f2c28f3 100644
@@ -464,7 +464,7 @@ struct ieee_param {
 #define RTLLIB_QCTL_TID	      0x000F
 
 #define	FC_QOS_BIT					BIT7
-#define IsDataFrame(pdu)	(((pdu[0] & 0x0C) == 0x08) ? true : false)
+#define IsDataFrame(pdu)	((pdu[0] & 0x0C) == 0x08)
 #define	IsLegacyDataFrame(pdu)	(IsDataFrame(pdu) && (!(pdu[0]&FC_QOS_BIT)))
 #define IsQoSDataFrame(pframe)			\
 	((*(u16 *)pframe&(RTLLIB_STYPE_QOS_DATA|RTLLIB_FTYPE_DATA)) ==	\
--

1.9.1

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

#2 lore raw
Quoted 43 lines · Julia Lawall
Quoted 39 lines · Bhumika Goyal

Relational and logical operators evaluate to either true or false. Explicit conversion is not needed so remove the ternary operator. Done using coccinelle:

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

---
 drivers/staging/rtl8192e/rtl819x_HTProc.c | 12 ++++--------
 drivers/staging/rtl8192e/rtllib.h         |  2 +-
 2 files changed, 5 insertions(+), 9 deletions(-)
drivers/staging/rtl8192e/rtl819x_HTProc.c +3 -6
index dd9c0c8..8cd51a9 100644
@@ -558,19 +558,15 @@ void HTOnAssocRsp(struct rtllib_device *ieee)
 #endif
      HTSetConnectBwMode(ieee, (enum ht_channel_width)(pPeerHTCap->ChlWidth),
                        (enum ht_extchnl_offset)(pPeerHTInfo->ExtChlOffset));
-     pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth == 1) ?
-                              true : false);
+     pHTInfo->bCurTxBW40MHz = (pPeerHTInfo->RecommemdedTxWidth == 1);
 
      pHTInfo->bCurShortGI20MHz = ((pHTInfo->bRegShortGI20MHz) ?
-                                 ((pPeerHTCap->ShortGI20Mhz == 1) ?
-                                 true : false) : false);
+                                 (pPeerHTCap->ShortGI20Mhz == 1) : false);
      pHTInfo->bCurShortGI40MHz = ((pHTInfo->bRegShortGI40MHz) ?
-                                  ((pPeerHTCap->ShortGI40Mhz == 1) ?
-                                  true : false) : false);
+                                  (pPeerHTCap->ShortGI40Mhz == 1) : false);
 
Quoted 8 lines

drivers/staging/rtl8192e/rtl819x_HTProc.c void HTOnAssocRsp(struct rtllib_device *ieee) · line 569

Quoted 4 lines
drivers/staging/rtl8192e/rtl819x_HTProc.c +1 -2
      pHTInfo->bCurSuppCCK = ((pHTInfo->bRegSuppCCK) ?
-                            ((pPeerHTCap->DssCCk == 1) ? true :
-                            false) : false);
+                            (pPeerHTCap->DssCCk == 1) : false);

Even with the simplification, these look like a mess. Could && and || be used here?

Yes, I think these can be further reduced to something like:
pHTInfo->bCurSuppCCK= (pHTInfo->bRegSuppCCK && pPeerHTCap->DssCCk); as the left hand side is true only if both the RHS values are true/1. Same reduction could be done for pHTInfo->bCurShortGI40MHz and pHTInfo->bCurShortGI20MHz.

Thanks,
Bhumika

Quoted 28 lines

julia

Quoted 26 lines
drivers/staging/rtl8192e/rtl819x_HTProc.c +0 -0
      pHTInfo->bCurrent_AMSDU_Support = pHTInfo->bAMSDU_Support;
drivers/staging/rtl8192e/rtllib.h +1 -2
index b895a53..f2c28f3 100644
@@ -464,7 +464,7 @@ struct ieee_param {
 #define RTLLIB_QCTL_TID            0x000F
 
 #define      FC_QOS_BIT                                      BIT7
-#define IsDataFrame(pdu)     (((pdu[0] & 0x0C) == 0x08) ? true : false)
+#define IsDataFrame(pdu)     ((pdu[0] & 0x0C) == 0x08)
 #define      IsLegacyDataFrame(pdu)  (IsDataFrame(pdu) && (!(pdu[0]&FC_QOS_BIT)))
 #define IsQoSDataFrame(pframe)                       \
      ((*(u16 *)pframe&(RTLLIB_STYPE_QOS_DATA|RTLLIB_FTYPE_DATA)) ==  \
--

1.9.1

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

#3 lore raw
Quoted 52 lines · Bhumika Goyal
Quoted 43 lines · Julia Lawall
Quoted 39 lines · Bhumika Goyal

Relational and logical operators evaluate to either true or false. Explicit conversion is not needed so remove the ternary operator. Done using coccinelle:

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

---
 drivers/staging/rtl8192e/rtl819x_HTProc.c | 12 ++++--------
 drivers/staging/rtl8192e/rtllib.h         |  2 +-
 2 files changed, 5 insertions(+), 9 deletions(-)
drivers/staging/rtl8192e/rtl819x_HTProc.c +3 -6
index dd9c0c8..8cd51a9 100644
@@ -558,19 +558,15 @@ void HTOnAssocRsp(struct rtllib_device *ieee)
 #endif
      HTSetConnectBwMode(ieee, (enum ht_channel_width)(pPeerHTCap->ChlWidth),
                        (enum ht_extchnl_offset)(pPeerHTInfo->ExtChlOffset));
-     pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth == 1) ?
-                              true : false);
+     pHTInfo->bCurTxBW40MHz = (pPeerHTInfo->RecommemdedTxWidth == 1);
 
      pHTInfo->bCurShortGI20MHz = ((pHTInfo->bRegShortGI20MHz) ?
-                                 ((pPeerHTCap->ShortGI20Mhz == 1) ?
-                                 true : false) : false);
+                                 (pPeerHTCap->ShortGI20Mhz == 1) : false);
      pHTInfo->bCurShortGI40MHz = ((pHTInfo->bRegShortGI40MHz) ?
-                                  ((pPeerHTCap->ShortGI40Mhz == 1) ?
-                                  true : false) : false);
+                                  (pPeerHTCap->ShortGI40Mhz == 1) : false);
 
Quoted 8 lines

drivers/staging/rtl8192e/rtl819x_HTProc.c void HTOnAssocRsp(struct rtllib_device *ieee) · line 569

Quoted 4 lines
drivers/staging/rtl8192e/rtl819x_HTProc.c +1 -2
      pHTInfo->bCurSuppCCK = ((pHTInfo->bRegSuppCCK) ?
-                            ((pPeerHTCap->DssCCk == 1) ? true :
-                            false) : false);
+                            (pPeerHTCap->DssCCk == 1) : false);

Even with the simplification, these look like a mess. Could && and || be used here?

Quoted 5 lines

Yes, I think these can be further reduced to something like:
pHTInfo->bCurSuppCCK= (pHTInfo->bRegSuppCCK && pPeerHTCap->DssCCk); as the left hand side is true only if both the RHS values are true/1. Same reduction could be done for pHTInfo->bCurShortGI40MHz and pHTInfo->bCurShortGI20MHz.

Is DssCCk boolean? If not you may need to keep the == 1.

julia

Quoted 40 lines

Thanks,
Bhumika

Quoted 21 lines

julia

Quoted 19 lines
drivers/staging/rtl8192e/rtl819x_HTProc.c +0 -0
      pHTInfo->bCurrent_AMSDU_Support = pHTInfo->bAMSDU_Support;
drivers/staging/rtl8192e/rtllib.h +1 -2
index b895a53..f2c28f3 100644
@@ -464,7 +464,7 @@ struct ieee_param {
 #define RTLLIB_QCTL_TID            0x000F
 
 #define      FC_QOS_BIT                                      BIT7
-#define IsDataFrame(pdu)     (((pdu[0] & 0x0C) == 0x08) ? true : false)
+#define IsDataFrame(pdu)     ((pdu[0] & 0x0C) == 0x08)
 #define      IsLegacyDataFrame(pdu)  (IsDataFrame(pdu) && (!(pdu[0]&FC_QOS_BIT)))
 #define IsQoSDataFrame(pframe)                       \
      ((*(u16 *)pframe&(RTLLIB_STYPE_QOS_DATA|RTLLIB_FTYPE_DATA)) ==  \
--

1.9.1

Quoted 7 lines
Quoted 7 lines

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

--
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/CAOH%2B1jGUWFyq5gJJq%3D1MhrjZjXyW0zeF4%2Bm8g%2BjvVPurerLg0w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

maintainer
#4 lore raw
In reply to Bhumika Goyal
Quoted 23 lines · Bhumika Goyal

Relational and logical operators evaluate to either true or false. Explicit conversion is not needed so remove the ternary operator. Done using coccinelle:

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

---
 drivers/staging/rtl8192e/rtl819x_HTProc.c | 12 ++++--------
 drivers/staging/rtl8192e/rtllib.h         |  2 +-
 2 files changed, 5 insertions(+), 9 deletions(-)
drivers/staging/rtl8192e/rtl819x_HTProc.c +0 -0
index dd9c0c8..8cd51a9 100644

drivers/staging/rtl8192e/rtl819x_HTProc.c void HTOnAssocRsp(struct rtllib_device *ieee) · line 561

Quoted 6 lines
drivers/staging/rtl8192e/rtl819x_HTProc.c +1 -2
@@ -558,19 +558,15 @@ void HTOnAssocRsp(struct rtllib_device *ieee)
 #endif
 	HTSetConnectBwMode(ieee, (enum ht_channel_width)(pPeerHTCap->ChlWidth),
 			  (enum ht_extchnl_offset)(pPeerHTInfo->ExtChlOffset));
-	pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth == 1) ?
-				 true : false);
+	pHTInfo->bCurTxBW40MHz = (pPeerHTInfo->RecommemdedTxWidth == 1);

Ugh, I _hate_ ? : statements.

Just write the thing out, is this easy to read as is?

drivers/staging/rtl8192e/rtl819x_HTProc.c void HTOnAssocRsp(struct rtllib_device *ieee) · line 566

Quoted 8 lines
drivers/staging/rtl8192e/rtl819x_HTProc.c +2 -4
 	pHTInfo->bCurShortGI20MHz = ((pHTInfo->bRegShortGI20MHz) ?
-				    ((pPeerHTCap->ShortGI20Mhz == 1) ?
-				    true : false) : false);
+				    (pPeerHTCap->ShortGI20Mhz == 1) : false);
 	pHTInfo->bCurShortGI40MHz = ((pHTInfo->bRegShortGI40MHz) ?
-				     ((pPeerHTCap->ShortGI40Mhz == 1) ?
-				     true : false) : false);
+				     (pPeerHTCap->ShortGI40Mhz == 1) : false);

Is this? Kernel code is meant to be read by humans first, and the compiler second. None of this will be any different if you write out a if () statement. Please just do that instead.

thanks,

greg k-h

#5 lore raw
Quoted 35 lines · Greg KH
Quoted 23 lines · Bhumika Goyal

Relational and logical operators evaluate to either true or false. Explicit conversion is not needed so remove the ternary operator. Done using coccinelle:

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

---
 drivers/staging/rtl8192e/rtl819x_HTProc.c | 12 ++++--------
 drivers/staging/rtl8192e/rtllib.h         |  2 +-
 2 files changed, 5 insertions(+), 9 deletions(-)
drivers/staging/rtl8192e/rtl819x_HTProc.c +0 -0
index dd9c0c8..8cd51a9 100644

drivers/staging/rtl8192e/rtl819x_HTProc.c void HTOnAssocRsp(struct rtllib_device *ieee) · line 561

Quoted 6 lines
drivers/staging/rtl8192e/rtl819x_HTProc.c +1 -2
@@ -558,19 +558,15 @@ void HTOnAssocRsp(struct rtllib_device *ieee)
 #endif
 	HTSetConnectBwMode(ieee, (enum ht_channel_width)(pPeerHTCap->ChlWidth),
 			  (enum ht_extchnl_offset)(pPeerHTInfo->ExtChlOffset));
-	pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth == 1) ?
-				 true : false);
+	pHTInfo->bCurTxBW40MHz = (pPeerHTInfo->RecommemdedTxWidth == 1);

Ugh, I _hate_ ? : statements.

Just write the thing out, is this easy to read as is?

Quoted 12 lines

drivers/staging/rtl8192e/rtl819x_HTProc.c void HTOnAssocRsp(struct rtllib_device *ieee) · line 566

Quoted 8 lines
drivers/staging/rtl8192e/rtl819x_HTProc.c +2 -4
 	pHTInfo->bCurShortGI20MHz = ((pHTInfo->bRegShortGI20MHz) ?
-				    ((pPeerHTCap->ShortGI20Mhz == 1) ?
-				    true : false) : false);
+				    (pPeerHTCap->ShortGI20Mhz == 1) : false);
 	pHTInfo->bCurShortGI40MHz = ((pHTInfo->bRegShortGI40MHz) ?
-				     ((pPeerHTCap->ShortGI40Mhz == 1) ?
-				     true : false) : false);
+				     (pPeerHTCap->ShortGI40Mhz == 1) : false);

Is this? Kernel code is meant to be read by humans first, and the compiler second. None of this will be any different if you write out a if () statement. Please just do that instead.

Wouldn't && or || be nicer if possible? If the == 1 are actually testing booleans, it could be quite concise.

julia

Quoted 12 lines

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 visit https://groups.google.com/d/msgid/outreachy-kernel/20161009142656.GA27065%40kroah.com.
For more options, visit https://groups.google.com/d/optout.

maintainer
#6 lore raw
Quoted 52 lines · Julia Lawall
Quoted 35 lines · Greg KH
Quoted 23 lines · Bhumika Goyal

Relational and logical operators evaluate to either true or false. Explicit conversion is not needed so remove the ternary operator. Done using coccinelle:

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

---
 drivers/staging/rtl8192e/rtl819x_HTProc.c | 12 ++++--------
 drivers/staging/rtl8192e/rtllib.h         |  2 +-
 2 files changed, 5 insertions(+), 9 deletions(-)
drivers/staging/rtl8192e/rtl819x_HTProc.c +0 -0
index dd9c0c8..8cd51a9 100644

drivers/staging/rtl8192e/rtl819x_HTProc.c void HTOnAssocRsp(struct rtllib_device *ieee) · line 561

Quoted 6 lines
drivers/staging/rtl8192e/rtl819x_HTProc.c +1 -2
@@ -558,19 +558,15 @@ void HTOnAssocRsp(struct rtllib_device *ieee)
 #endif
 	HTSetConnectBwMode(ieee, (enum ht_channel_width)(pPeerHTCap->ChlWidth),
 			  (enum ht_extchnl_offset)(pPeerHTInfo->ExtChlOffset));
-	pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth == 1) ?
-				 true : false);
+	pHTInfo->bCurTxBW40MHz = (pPeerHTInfo->RecommemdedTxWidth == 1);

Ugh, I _hate_ ? : statements.

Just write the thing out, is this easy to read as is?

Quoted 12 lines

drivers/staging/rtl8192e/rtl819x_HTProc.c void HTOnAssocRsp(struct rtllib_device *ieee) · line 566

Quoted 8 lines
drivers/staging/rtl8192e/rtl819x_HTProc.c +2 -4
 	pHTInfo->bCurShortGI20MHz = ((pHTInfo->bRegShortGI20MHz) ?
-				    ((pPeerHTCap->ShortGI20Mhz == 1) ?
-				    true : false) : false);
+				    (pPeerHTCap->ShortGI20Mhz == 1) : false);
 	pHTInfo->bCurShortGI40MHz = ((pHTInfo->bRegShortGI40MHz) ?
-				     ((pPeerHTCap->ShortGI40Mhz == 1) ?
-				     true : false) : false);
+				     (pPeerHTCap->ShortGI40Mhz == 1) : false);

Is this? Kernel code is meant to be read by humans first, and the compiler second. None of this will be any different if you write out a if () statement. Please just do that instead.

Quoted 2 lines

Wouldn't && or || be nicer if possible? If the == 1 are actually testing booleans, it could be quite concise.

Yes, maybe, but never ? : if at all possible (as function arguments it makes sense.)

thanks,

greg k-h

#7 lore raw
Quoted 53 lines · Greg KH
Quoted 52 lines · Julia Lawall
Quoted 47 lines · Greg KH
Quoted 23 lines · Bhumika Goyal

Relational and logical operators evaluate to either true or false. Explicit conversion is not needed so remove the ternary operator. Done using coccinelle:

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

---
 drivers/staging/rtl8192e/rtl819x_HTProc.c | 12 ++++--------
 drivers/staging/rtl8192e/rtllib.h         |  2 +-
 2 files changed, 5 insertions(+), 9 deletions(-)
drivers/staging/rtl8192e/rtl819x_HTProc.c +0 -0
index dd9c0c8..8cd51a9 100644

drivers/staging/rtl8192e/rtl819x_HTProc.c void HTOnAssocRsp(struct rtllib_device *ieee) · line 561

Quoted 6 lines
drivers/staging/rtl8192e/rtl819x_HTProc.c +1 -2
@@ -558,19 +558,15 @@ void HTOnAssocRsp(struct rtllib_device *ieee)
 #endif
  HTSetConnectBwMode(ieee, (enum ht_channel_width)(pPeerHTCap->ChlWidth),
                    (enum ht_extchnl_offset)(pPeerHTInfo->ExtChlOffset));
- pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth == 1) ?
-                          true : false);
+ pHTInfo->bCurTxBW40MHz = (pPeerHTInfo->RecommemdedTxWidth == 1);

Ugh, I _hate_ ? : statements.

Just write the thing out, is this easy to read as is?

drivers/staging/rtl8192e/rtl819x_HTProc.c void HTOnAssocRsp(struct rtllib_device *ieee) · line 566

Quoted 8 lines
drivers/staging/rtl8192e/rtl819x_HTProc.c +2 -4
  pHTInfo->bCurShortGI20MHz = ((pHTInfo->bRegShortGI20MHz) ?
-                             ((pPeerHTCap->ShortGI20Mhz == 1) ?
-                             true : false) : false);
+                             (pPeerHTCap->ShortGI20Mhz == 1) : false);
  pHTInfo->bCurShortGI40MHz = ((pHTInfo->bRegShortGI40MHz) ?
-                              ((pPeerHTCap->ShortGI40Mhz == 1) ?
-                              true : false) : false);
+                              (pPeerHTCap->ShortGI40Mhz == 1) : false);

Is this? Kernel code is meant to be read by humans first, and the compiler second. None of this will be any different if you write out a if () statement. Please just do that instead.

Quoted 6 lines
Quoted 2 lines

Wouldn't && or || be nicer if possible? If the == 1 are actually testing booleans, it could be quite concise.

Yes, maybe, but never ? : if at all possible (as function arguments it makes sense.)

Okay, I will convert all these ?: operators into if() statements. Thanks for the feedback Julia and Greg.

Thanks,
Bhumika

Quoted 3 lines

thanks,

greg k-h