* [PATCH] Staging: rtlwifi: Remove unwanted parentheses
@ 2019-04-03 16:04 Madhumitha Prabakaran
2019-04-03 16:18 ` Dan Carpenter
0 siblings, 1 reply; 4+ messages in thread
From: Madhumitha Prabakaran @ 2019-04-03 16:04 UTC (permalink / raw)
To: gregkh, devel, linux-kernel; +Cc: Madhumitha Prabakaran
Remove unwanted parentheses around right hand side of an assignment to
make code better and more understandable.
Issue found by Coccinelle.
Signed-off-by: Madhumitha Prabakaran <madhumithabiw@gmail.com>
---
drivers/staging/rtlwifi/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/rtlwifi/core.c b/drivers/staging/rtlwifi/core.c
index a9902818ae7e..970343048b69 100644
--- a/drivers/staging/rtlwifi/core.c
+++ b/drivers/staging/rtlwifi/core.c
@@ -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;
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Staging: rtlwifi: Remove unwanted parentheses
2019-04-03 16:04 [PATCH] Staging: rtlwifi: Remove unwanted parentheses Madhumitha Prabakaran
@ 2019-04-03 16:18 ` Dan Carpenter
2019-04-03 16:21 ` Dan Carpenter
0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2019-04-03 16:18 UTC (permalink / raw)
To: Madhumitha Prabakaran; +Cc: gregkh, devel, linux-kernel
On Wed, Apr 03, 2019 at 11:04:45AM -0500, Madhumitha Prabakaran wrote:
> Remove unwanted parentheses around right hand side of an assignment to
> make code better and more understandable.
>
> Issue found by Coccinelle.
>
> Signed-off-by: Madhumitha Prabakaran <madhumithabiw@gmail.com>
> ---
> drivers/staging/rtlwifi/core.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/rtlwifi/core.c b/drivers/staging/rtlwifi/core.c
> index a9902818ae7e..970343048b69 100644
> --- a/drivers/staging/rtlwifi/core.c
> +++ b/drivers/staging/rtlwifi/core.c
> @@ -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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Staging: rtlwifi: Remove unwanted parentheses
2019-04-03 16:18 ` Dan Carpenter
@ 2019-04-03 16:21 ` Dan Carpenter
2019-04-03 22:50 ` Madhumthia Prabakaran
0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2019-04-03 16:21 UTC (permalink / raw)
To: Madhumitha Prabakaran; +Cc: gregkh, devel, linux-kernel
On Wed, Apr 03, 2019 at 07:18:03PM +0300, Dan Carpenter wrote:
> data_bit = (data & BIT(i)) ? 1 : 0;
I quite like the !! idiom also...
data_bit = !!(data & BIT(i));
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Staging: rtlwifi: Remove unwanted parentheses
2019-04-03 16:21 ` Dan Carpenter
@ 2019-04-03 22:50 ` Madhumthia Prabakaran
0 siblings, 0 replies; 4+ messages in thread
From: Madhumthia Prabakaran @ 2019-04-03 22:50 UTC (permalink / raw)
To: Dan Carpenter, gregkh, devel, linux-kernel
On Wed, Apr 03, 2019 at 07:21:45PM +0300, Dan Carpenter wrote:
> On Wed, Apr 03, 2019 at 07:18:03PM +0300, Dan Carpenter wrote:
> > data_bit = (data & BIT(i)) ? 1 : 0;
>
> I quite like the !! idiom also...
>
> data_bit = !!(data & BIT(i));
Thanks for reviewing it.
>
> regards,
> dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-04-03 22:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-03 16:04 [PATCH] Staging: rtlwifi: Remove unwanted parentheses Madhumitha Prabakaran
2019-04-03 16:18 ` Dan Carpenter
2019-04-03 16:21 ` Dan Carpenter
2019-04-03 22:50 ` Madhumthia Prabakaran
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.