* [PATCH v3] Staging: rtlwifi: Cleanup crc16_ccitt()
@ 2019-04-04 19:51 Madhumitha Prabakaran
2019-04-05 5:00 ` Dan Carpenter
0 siblings, 1 reply; 2+ messages in thread
From: Madhumitha Prabakaran @ 2019-04-04 19:51 UTC (permalink / raw)
To: gregkh, devel, linux-kernel; +Cc: Madhumitha Prabakaran
crc16_ccitt() function does "BIT(0) << i" instead of "BIT(i)".
Using !! is slightly shorter than "foo ? 1: 0" and remove unnecessary
parentheses to make the code simple.
Issue suggested by Coccinelle.
Signed-off-by: Madhumitha Prabakaran <madhumithabiw@gmail.com>
---
Changes in v3:
- Changed subject line and commit log
- Removed unnecessary parentheses in the function
Changes in v2:
- Changed commit log
- Replaced ternary operator with !! idiom
- Modified a BIT operator
---
drivers/staging/rtlwifi/core.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/staging/rtlwifi/core.c b/drivers/staging/rtlwifi/core.c
index a9902818ae7e..2cce65368f92 100644
--- a/drivers/staging/rtlwifi/core.c
+++ b/drivers/staging/rtlwifi/core.c
@@ -341,25 +341,25 @@ 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));
+ data_bit = !!(data & BIT(i));
shift_in = crc_bit15 ^ data_bit;
result = crc << 1;
if (shift_in == 0)
- result &= (~BIT(0));
+ result &= ~BIT(0);
else
result |= BIT(0);
- crc_bit11 = ((crc & BIT(11)) ? 1 : 0) ^ shift_in;
+ crc_bit11 = !!(crc & BIT(11)) ^ shift_in;
if (crc_bit11 == 0)
- result &= (~BIT(12));
+ result &= ~BIT(12);
else
result |= BIT(12);
- crc_bit4 = ((crc & BIT(4)) ? 1 : 0) ^ shift_in;
+ crc_bit4 = !!(crc & BIT(4)) ^ shift_in;
if (crc_bit4 == 0)
- result &= (~BIT(5));
+ result &= ~BIT(5);
else
result |= BIT(5);
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] Staging: rtlwifi: Cleanup crc16_ccitt()
2019-04-04 19:51 [PATCH v3] Staging: rtlwifi: Cleanup crc16_ccitt() Madhumitha Prabakaran
@ 2019-04-05 5:00 ` Dan Carpenter
0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2019-04-05 5:00 UTC (permalink / raw)
To: Madhumitha Prabakaran; +Cc: gregkh, devel, linux-kernel
Thanks!
Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-04-05 5:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-04 19:51 [PATCH v3] Staging: rtlwifi: Cleanup crc16_ccitt() Madhumitha Prabakaran
2019-04-05 5:00 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).