Skip to contentSkip to conversation

staging: rtl8712: Remove redundant braces in if statements

PATCH In review Sergey Rozhnov 5 participants 5 messages Jul 21, 2023 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rtl8712: Remove redundant braces in if statements

Extract masked value to improve readability, apply fix suggested by checkpatch.

---
 drivers/staging/rtl8712/ieee80211.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/rtl8712/ieee80211.c +3 -2
index 7d8f1a29d18a..fe53453ab9a7 100644
@@ -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++;
 	}
Signature · 1 line
2.40.1
#1 lore raw
Quoted 25 lines · Sergey Rozhnov

Extract masked value to improve readability, apply fix suggested by checkpatch.

---
 drivers/staging/rtl8712/ieee80211.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/rtl8712/ieee80211.c +3 -2
index 7d8f1a29d18a..fe53453ab9a7 100644
@@ -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++;
 	}
Signature · 1 line
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

#2 lore raw
In reply to Sergey Rozhnov
Quoted 11 lines · Sergey Rozhnov

Extract masked value to improve readability, apply fix suggested by checkpatch.

---
  drivers/staging/rtl8712/ieee80211.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/rtl8712/ieee80211.c +0 -0
index 7d8f1a29d18a..fe53453ab9a7 100644
@@ -63,8 +63,9 @@ uint r8712_is_cckrates_included(u8 *rate)
  	u32 i = 0;

drivers/staging/rtl8712/ieee80211.c uint r8712_is_cckrates_included(u8 *rate) · line 71

Quoted 10 lines
drivers/staging/rtl8712/ieee80211.c +3 -2
 
  	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

#3 lore raw
In reply to Sergey Rozhnov
Quoted 2 lines · Sergey Rozhnov

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

#4 lore raw
Quoted 6 lines · Dan Carpenter
Quoted 2 lines · Sergey Rozhnov

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.