[PATCH] staging: rtl8712: Remove redundant braces in if statements

Sergey Rozhnov posted 1 patch 2 years, 6 months ago
drivers/staging/rtl8712/ieee80211.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
[PATCH] staging: rtl8712: Remove redundant braces in if statements
Posted by Sergey Rozhnov 2 years, 6 months ago
Extract masked value to improve readability, apply fix suggested by checkpatch.
---
 drivers/staging/rtl8712/ieee80211.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8712/ieee80211.c b/drivers/staging/rtl8712/ieee80211.c
index 7d8f1a29d18a..fe53453ab9a7 100644
--- a/drivers/staging/rtl8712/ieee80211.c
+++ b/drivers/staging/rtl8712/ieee80211.c
@@ -63,8 +63,9 @@ uint r8712_is_cckrates_included(u8 *rate)
 	u32 i = 0;
 
 	while (rate[i] != 0) {
-		if ((((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
-		    (((rate[i]) & 0x7f) == 11) || (((rate[i]) & 0x7f) == 22))
+		u8 val = rate[i] & 0x7f;
+
+		if (val == 2 || val == 4 || val == 11 || val == 22)
 			return true;
 		i++;
 	}
-- 
2.40.1
Re: [PATCH] staging: rtl8712: Remove redundant braces in if statements
Posted by Dan Carpenter 2 years, 6 months ago
On Fri, Jul 21, 2023 at 06:05:57AM +0400, Sergey Rozhnov wrote:
> Extract masked value to improve readability, apply fix suggested by checkpatch.
> ---

I like the new format, but you need to run checkpatch on your patches.

regards,
dan carpenter
Re: [PATCH] staging: rtl8712: Remove redundant braces in if statements
Posted by Joe Perches 2 years, 6 months ago
On Fri, 2023-07-21 at 09:01 +0300, Dan Carpenter wrote:
> On Fri, Jul 21, 2023 at 06:05:57AM +0400, Sergey Rozhnov wrote:
> > Extract masked value to improve readability, apply fix suggested by checkpatch.
> > ---
> 
> I like the new format, but you need to run checkpatch on your patches.
> 

True, but this does only 1 of 2 very similar functions.
Ideally both would be done at the same time.

My preference would be to remove the int i and just
dereference rate similar to:

uint r8712_is_cckrates_included(u8 *rate)
{
	while (*rate) {
		u8 r = *rate & 0x7f;

		if (r == 2 || r == 4 || r == 11 || r == 22)
			return true;
		rate++;
	}

	return false;
}

uint r8712_is_cckratesonly_included(u8 *rate)
{
	while (*rate) {
		u8 r = *rate & 0x7f;

		if (r != 2 && r != 4 && r != 11  && r != 22)
			return false;
		rate++;
	}

	return true;
}

though the existing cckratesonly_included function
seemingly returns an incorrect true if the rate array
is empty.
Re: [PATCH] staging: rtl8712: Remove redundant braces in if statements
Posted by Larry Finger 2 years, 6 months ago
On 7/20/23 21:05, Sergey Rozhnov wrote:
> Extract masked value to improve readability, apply fix suggested by checkpatch.
> ---
>   drivers/staging/rtl8712/ieee80211.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/rtl8712/ieee80211.c b/drivers/staging/rtl8712/ieee80211.c
> index 7d8f1a29d18a..fe53453ab9a7 100644
> --- a/drivers/staging/rtl8712/ieee80211.c
> +++ b/drivers/staging/rtl8712/ieee80211.c
> @@ -63,8 +63,9 @@ uint r8712_is_cckrates_included(u8 *rate)
>   	u32 i = 0;
>   
>   	while (rate[i] != 0) {
> -		if ((((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
> -		    (((rate[i]) & 0x7f) == 11) || (((rate[i]) & 0x7f) == 22))
> +		u8 val = rate[i] & 0x7f;
> +
> +		if (val == 2 || val == 4 || val == 11 || val == 22)
>   			return true;
>   		i++;
>   	}

The value of such a patch is marginal. The compiler will optimize it and only 
calculate the value of rate[i] & 0x7f once, and keep it in a register, which is 
likely what happens with your change as val will never be used again. Checkpatch 
is only suggestive and can be ignored.

You have no signed-off-by tag. As such, this patch could never be applied as it 
has no one vouching that they are the author. Please read and follow the 
instructions for submitting patches.

Larry
Re: [PATCH] staging: rtl8712: Remove redundant braces in if statements
Posted by Greg Kroah-Hartman 2 years, 6 months ago
On Fri, Jul 21, 2023 at 06:05:57AM +0400, Sergey Rozhnov wrote:
> Extract masked value to improve readability, apply fix suggested by checkpatch.
> ---
>  drivers/staging/rtl8712/ieee80211.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/rtl8712/ieee80211.c b/drivers/staging/rtl8712/ieee80211.c
> index 7d8f1a29d18a..fe53453ab9a7 100644
> --- a/drivers/staging/rtl8712/ieee80211.c
> +++ b/drivers/staging/rtl8712/ieee80211.c
> @@ -63,8 +63,9 @@ uint r8712_is_cckrates_included(u8 *rate)
>  	u32 i = 0;
>  
>  	while (rate[i] != 0) {
> -		if ((((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
> -		    (((rate[i]) & 0x7f) == 11) || (((rate[i]) & 0x7f) == 22))
> +		u8 val = rate[i] & 0x7f;
> +
> +		if (val == 2 || val == 4 || val == 11 || val == 22)
>  			return true;
>  		i++;
>  	}
> -- 
> 2.40.1
> 
> 

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
a patch that has triggered this response.  He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created.  Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.

You are receiving this message because of the following common error(s)
as indicated below:

- Your patch does not have a Signed-off-by: line.  Please read the
  kernel file, Documentation/process/submitting-patches.rst and resend
  it after adding that line.  Note, the line needs to be in the body of
  the email, before the patch, not at the bottom of the patch or in the
  email signature.

- You did not specify a description of why the patch is needed, or
  possibly, any description at all, in the email body.  Please read the
  section entitled "The canonical patch format" in the kernel file,
  Documentation/process/submitting-patches.rst for what is needed in
  order to properly describe the change.

If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.

thanks,

greg k-h's patch email bot