public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] Staging: rtlwifi: Remove unwanted parentheses
@ 2019-04-03 22:38 Madhumitha Prabakaran
  2019-04-04  9:09 ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Madhumitha Prabakaran @ 2019-04-03 22:38 UTC (permalink / raw)
  To: gregkh, devel, linux-kernel; +Cc: Madhumitha Prabakaran

Remove unwanted parentheses and use !! idiom in place of ternary
operator to make code simple and more understandable.

Signed-off-by: Madhumitha Prabakaran <madhumithabiw@gmail.com>

---
Changes in v2:
- Changed commit log
- Replaced ternary operator with !! idiom
- Modified a BIT operator
---
 drivers/staging/rtlwifi/core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtlwifi/core.c b/drivers/staging/rtlwifi/core.c
index a9902818ae7e..c70f062cf4b9 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));
+		data_bit  = !!(data & BIT(i));
 		shift_in = crc_bit15 ^ data_bit;
 
 		result = crc << 1;
@@ -351,13 +351,13 @@ static u16 crc16_ccitt(u8 data, u16 crc)
 		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));
 		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));
 		else
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] Staging: rtlwifi: Remove unwanted parentheses
  2019-04-03 22:38 [PATCH v2] Staging: rtlwifi: Remove unwanted parentheses Madhumitha Prabakaran
@ 2019-04-04  9:09 ` Dan Carpenter
  2019-04-04 19:56   ` Madhumthia Prabakaran
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2019-04-04  9:09 UTC (permalink / raw)
  To: Madhumitha Prabakaran; +Cc: gregkh, devel, linux-kernel

You should probably update the subject line because now it's not just
about parentheses any more.

[PATCH v2] Staging: rtlwifi: clean up crc16_ccitt()

So the one thing per patch rule is a little bit about selling your
patch.  We never allow "Clean up whole_file.c" but we do sometimes allow
"Clean up a function()" so long as the patch description sells it in
the right way.

Blah blah function does "BIT(0) << i" instead of "BIT(i)".  Using !!
is slightly shorter than "foo ? 1 : 0".  Blah blah, etc.

On Wed, Apr 03, 2019 at 05:38:51PM -0500, Madhumitha Prabakaran wrote:
> @@ -351,13 +351,13 @@ static u16 crc16_ccitt(u8 data, u16 crc)
>  		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));
                                  ^        ^
I thought your Coccinelle script was going to complain about these
parentheses.  Probably the &= confuses it?  There are a couple others
in the same function.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] Staging: rtlwifi: Remove unwanted parentheses
  2019-04-04  9:09 ` Dan Carpenter
@ 2019-04-04 19:56   ` Madhumthia Prabakaran
  0 siblings, 0 replies; 3+ messages in thread
From: Madhumthia Prabakaran @ 2019-04-04 19:56 UTC (permalink / raw)
  To: Dan Carpenter, gregkh, devel, linux-kernel

On Thu, Apr 04, 2019 at 12:09:00PM +0300, Dan Carpenter wrote:
> You should probably update the subject line because now it's not just
> about parentheses any more.
> 
> [PATCH v2] Staging: rtlwifi: clean up crc16_ccitt()
> 
> So the one thing per patch rule is a little bit about selling your
> patch.  We never allow "Clean up whole_file.c" but we do sometimes allow
> "Clean up a function()" so long as the patch description sells it in
> the right way.
> 
> Blah blah function does "BIT(0) << i" instead of "BIT(i)".  Using !!
> is slightly shorter than "foo ? 1 : 0".  Blah blah, etc.


Thanks for feedback!

> 
> On Wed, Apr 03, 2019 at 05:38:51PM -0500, Madhumitha Prabakaran wrote:
> > @@ -351,13 +351,13 @@ static u16 crc16_ccitt(u8 data, u16 crc)
> >  		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));
>                                   ^        ^
> I thought your Coccinelle script was going to complain about these
> parentheses.  Probably the &= confuses it?  There are a couple others
> in the same function.

I didn't included assignment operators in the earlier Coccinelle script. However, I
edited it now.

> 
> regards,
> dan carpenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-04-04 19:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-03 22:38 [PATCH v2] Staging: rtlwifi: Remove unwanted parentheses Madhumitha Prabakaran
2019-04-04  9:09 ` Dan Carpenter
2019-04-04 19:56   ` Madhumthia Prabakaran

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox