Skip to contentSkip to conversation

Staging: rtlwifi: Remove unwanted parentheses

PATCH Superseded Madhumitha Prabakaran 2 participants 4 messages Apr 3, 2019 Staging

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: rtlwifi: Remove unwanted parentheses

Remove unwanted parentheses around right hand side of an assignment to make code better and more understandable.

Issue found by Coccinelle.

---
 drivers/staging/rtlwifi/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtlwifi/core.c +2 -2
index a9902818ae7e..970343048b69 100644
@@ -341,8 +341,8 @@ static u16 crc16_ccitt(u8 data, u16 crc)
 	u16 result;
 
 	for (i = 0; i < 8; i++) {
-		crc_bit15 = ((crc & BIT(15)) ? 1 : 0);
-		data_bit  = (data & (BIT(0) << i) ? 1 : 0);
+		crc_bit15 = (crc & BIT(15)) ? 1 : 0;
+		data_bit  = data & (BIT(0) << i) ? 1 : 0;
 		shift_in = crc_bit15 ^ data_bit;
 
 		result = crc << 1;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 15 lines · Madhumitha Prabakaran

Remove unwanted parentheses around right hand side of an assignment to make code better and more understandable.

Issue found by Coccinelle.

---
 drivers/staging/rtlwifi/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtlwifi/core.c +0 -0
index a9902818ae7e..970343048b69 100644

drivers/staging/rtlwifi/core.c static u16 crc16_ccitt(u8 data, u16 crc) · line 345

Quoted 7 lines
drivers/staging/rtlwifi/core.c +2 -2
@@ -341,8 +341,8 @@ static u16 crc16_ccitt(u8 data, u16 crc)
 	u16 result;
 
 	for (i = 0; i < 8; i++) {
-		crc_bit15 = ((crc & BIT(15)) ? 1 : 0);
-		data_bit  = (data & (BIT(0) << i) ? 1 : 0);
+		crc_bit15 = (crc & BIT(15)) ? 1 : 0;
+		data_bit  = data & (BIT(0) << i) ? 1 : 0;

The original is obviously unhelpful, yes. And the code works correctly, true. But my preferred format would be like this:

		data_bit  = (data & BIT(i)) ? 1 : 0;

Left shifting BIT() is silly. But I like the extra parentheses around the bitwise AND operation because that's a hard precedence to remember.

regards,
dan carpenter

#2 lore raw
Quoted 1 line · Dan Carpenter
		data_bit  = (data & BIT(i)) ? 1 : 0;

I quite like the !! idiom also...

		data_bit = !!(data & BIT(i));

regards,
dan carpenter

#3 lore raw
Quoted 6 lines · Dan Carpenter
Quoted 1 line · Dan Carpenter
		data_bit  = (data & BIT(i)) ? 1 : 0;

I quite like the !! idiom also...

		data_bit = !!(data & BIT(i));

Thanks for reviewing it.

Quoted 3 lines

regards,
dan carpenter