Skip to contentSkip to conversation

staging: r8188eu: fix too many leading tabs

PATCH Superseded Joash Naidoo 4 participants 4 messages Sep 18, 2022 – Sep 19, 2022 Staging

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: r8188eu: fix too many leading tabs

Coding style fix. Fix too many leading tabs and line length. Convert __constant_htons to htons

---
 drivers/staging/r8188eu/core/rtw_br_ext.c | 66 ++++++++++++-----------
 1 file changed, 35 insertions(+), 31 deletions(-)
drivers/staging/r8188eu/core/rtw_br_ext.c +35 -31
index bca20fe5c..8e951fc0e 100644
@@ -604,37 +604,41 @@ void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
 	if (!skb)
 		return;
 
-	if (!priv->ethBrExtInfo.dhcp_bcst_disable) {
-		__be16 protocol = *((__be16 *)(skb->data + 2 * ETH_ALEN));
-
-		if (protocol == __constant_htons(ETH_P_IP)) { /*  IP */
-			struct iphdr *iph = (struct iphdr *)(skb->data + ETH_HLEN);
-
-			if (iph->protocol == IPPROTO_UDP) { /*  UDP */
-				struct udphdr *udph = (struct udphdr *)((size_t)iph + (iph->ihl << 2));
-
-				if ((udph->source == __constant_htons(CLIENT_PORT)) &&
-				    (udph->dest == __constant_htons(SERVER_PORT))) { /*  DHCP request */
-					struct dhcpMessage *dhcph =
-						(struct dhcpMessage *)((size_t)udph + sizeof(struct udphdr));
-					u32 cookie = be32_to_cpu((__be32)dhcph->cookie);
-
-					if (cookie == DHCP_MAGIC) { /*  match magic word */
-						if (!(dhcph->flags & htons(BROADCAST_FLAG))) {
-							/*  if not broadcast */
-							register int sum = 0;
-
-							/*  or BROADCAST flag */
-							dhcph->flags |= htons(BROADCAST_FLAG);
-							/*  recalculate checksum */
-							sum = ~(udph->check) & 0xffff;
-							sum += be16_to_cpu(dhcph->flags);
-							while (sum >> 16)
-								sum = (sum & 0xffff) + (sum >> 16);
-							udph->check = ~sum;
-						}
-					}
-				}
+	if (priv->ethBrExtInfo.dhcp_bcst_disable)
+		return;
+
+	__be16 protocol = *((__be16 *)(skb->data + 2 * ETH_ALEN));
+
+	if (protocol != htons(ETH_P_IP)) /*  IP */
+		return;
+
+	struct iphdr *iph = (struct iphdr *)(skb->data + ETH_HLEN);
+
+	if (iph->protocol != IPPROTO_UDP) /*  UDP */
+		return;
+
+	struct udphdr *udph = (struct udphdr *)((size_t)iph + (iph->ihl << 2));
+
+	if ((udph->source == htons(CLIENT_PORT)) &&
+	    (udph->dest == htons(SERVER_PORT))) { /*  DHCP request */
+		struct dhcpMessage *dhcph =
+			(struct dhcpMessage *)((size_t)udph +
+						   sizeof(struct udphdr));
+		u32 cookie = be32_to_cpu((__be32)dhcph->cookie);
+
+		if (cookie == DHCP_MAGIC) { /*  match magic word */
+			if (!(dhcph->flags & htons(BROADCAST_FLAG))) {
+				/*  if not broadcast */
+				register int sum = 0;
+
+				/*  or BROADCAST flag */
+				dhcph->flags |= htons(BROADCAST_FLAG);
+				/*  recalculate checksum */
+				sum = ~(udph->check) & 0xffff;
+				sum += be16_to_cpu(dhcph->flags);
+				while (sum >> 16)
+					sum = (sum & 0xffff) + (sum >> 16);
+				udph->check = ~sum;
 			}
 		}
 	}
Signature · 1 line
2.35.1
#1 lore raw
Quoted 75 lines · Joash Naidoo

Coding style fix. Fix too many leading tabs and line length. Convert __constant_htons to htons

---
  drivers/staging/r8188eu/core/rtw_br_ext.c | 66 ++++++++++++-----------
  1 file changed, 35 insertions(+), 31 deletions(-)
drivers/staging/r8188eu/core/rtw_br_ext.c +28 -31
index bca20fe5c..8e951fc0e 100644
@@ -604,37 +604,41 @@ void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
  	if (!skb)
  		return;
 
-	if (!priv->ethBrExtInfo.dhcp_bcst_disable) {
-		__be16 protocol = *((__be16 *)(skb->data + 2 * ETH_ALEN));
-
-		if (protocol == __constant_htons(ETH_P_IP)) { /*  IP */
-			struct iphdr *iph = (struct iphdr *)(skb->data + ETH_HLEN);
-
-			if (iph->protocol == IPPROTO_UDP) { /*  UDP */
-				struct udphdr *udph = (struct udphdr *)((size_t)iph + (iph->ihl << 2));
-
-				if ((udph->source == __constant_htons(CLIENT_PORT)) &&
-				    (udph->dest == __constant_htons(SERVER_PORT))) { /*  DHCP request */
-					struct dhcpMessage *dhcph =
-						(struct dhcpMessage *)((size_t)udph + sizeof(struct udphdr));
-					u32 cookie = be32_to_cpu((__be32)dhcph->cookie);
-
-					if (cookie == DHCP_MAGIC) { /*  match magic word */
-						if (!(dhcph->flags & htons(BROADCAST_FLAG))) {
-							/*  if not broadcast */
-							register int sum = 0;
-
-							/*  or BROADCAST flag */
-							dhcph->flags |= htons(BROADCAST_FLAG);
-							/*  recalculate checksum */
-							sum = ~(udph->check) & 0xffff;
-							sum += be16_to_cpu(dhcph->flags);
-							while (sum >> 16)
-								sum = (sum & 0xffff) + (sum >> 16);
-							udph->check = ~sum;
-						}
-					}
-				}
+	if (priv->ethBrExtInfo.dhcp_bcst_disable)
+		return;
+
+	__be16 protocol = *((__be16 *)(skb->data + 2 * ETH_ALEN));
+
+	if (protocol != htons(ETH_P_IP)) /*  IP */
+		return;
+
+	struct iphdr *iph = (struct iphdr *)(skb->data + ETH_HLEN);
+
+	if (iph->protocol != IPPROTO_UDP) /*  UDP */
+		return;
+
+	struct udphdr *udph = (struct udphdr *)((size_t)iph + (iph->ihl << 2));
+
+	if ((udph->source == htons(CLIENT_PORT)) &&
+	    (udph->dest == htons(SERVER_PORT))) { /*  DHCP request */
+		struct dhcpMessage *dhcph =
+			(struct dhcpMessage *)((size_t)udph +
+						   sizeof(struct udphdr));
+		u32 cookie = be32_to_cpu((__be32)dhcph->cookie);
+
+		if (cookie == DHCP_MAGIC) { /*  match magic word */
+			if (!(dhcph->flags & htons(BROADCAST_FLAG))) {
+				/*  if not broadcast */
+				register int sum = 0;
+
+				/*  or BROADCAST flag */

drivers/staging/r8188eu/core/rtw_br_ext.c void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb) · line 644

Quoted 10 lines
drivers/staging/r8188eu/core/rtw_br_ext.c +7 -0
+				dhcph->flags |= htons(BROADCAST_FLAG);
+				/*  recalculate checksum */
+				sum = ~(udph->check) & 0xffff;
+				sum += be16_to_cpu(dhcph->flags);
+				while (sum >> 16)
+					sum = (sum & 0xffff) + (sum >> 16);
+				udph->check = ~sum;
  			}
  		}
  	}

Hi

I was able to apply your patch.

I was able to compile it but the following warnings appeared:

kernel@matrix-ESPRIMO-P710:~/Documents/git/kernels/staging$ make -C . M=drivers/staging/r8188eu/
make: Entering directory '/home/kernel/Documents/git/kernels/staging'
  CC [M]  drivers/staging/r8188eu/core/rtw_br_ext.o
drivers/staging/r8188eu/core/rtw_br_ext.c: In function ‘dhcp_flag_bcast’:
drivers/staging/r8188eu/core/rtw_br_ext.c:610:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  610 |  __be16 protocol = *((__be16 *)(skb->data + 2 * ETH_ALEN));
      |  ^~~~~~
drivers/staging/r8188eu/core/rtw_br_ext.c:615:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  615 |  struct iphdr *iph = (struct iphdr *)(skb->data + ETH_HLEN);
      |  ^~~~~~
drivers/staging/r8188eu/core/rtw_br_ext.c:620:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  620 |  struct udphdr *udph = (struct udphdr *)((size_t)iph + 
(iph->ihl << 2));
      |  ^~~~~~
  LD [M]  drivers/staging/r8188eu/r8188eu.o
  MODPOST drivers/staging/r8188eu/Module.symvers
  CC [M]  drivers/staging/r8188eu/r8188eu.mod.o
  LD [M]  drivers/staging/r8188eu/r8188eu.ko
make: Leaving directory '/home/kernel/Documents/git/kernels/staging'

Do you have the hardware to tested this code and have you tested it?

checkpatch:
ERROR: trailing whitespace
#74: FILE: /home/kernel/Downloads/PATCH-staging-r8188eu-fix-too-many-leading-tabs.txt:74:
+ $

ERROR: trailing whitespace
#144: FILE: /home/kernel/Downloads/PATCH-staging-r8188eu-fix-too-many-leading-tabs.txt:144:
+-- $

total: 2 errors, 0 warnings, 147 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or
--fix-inplace.

NOTE: Whitespace errors detected.
You may wish to use scripts/cleanpatch or scripts/cleanfile

/home/kernel/Downloads/PATCH-staging-r8188eu-fix-too-many-leading-tabs.txt has style problems, please review.

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

On a simple download test it workes on my hardware.

Thanks for your support.

Bye Philipp

maintainer
#2 lore raw
In reply to Joash Naidoo
Quoted 7 lines · Joash Naidoo

Coding style fix. Fix too many leading tabs and line length. Convert __constant_htons to htons

---
 drivers/staging/r8188eu/core/rtw_br_ext.c | 66 ++++++++++++-----------
 1 file changed, 35 insertions(+), 31 deletions(-)

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 did many different things all at once, making it difficult to review. All Linux kernel patches need to only do one thing at a time. If you need to do multiple things (such as clean up all coding style issues in a file/driver), do it in a sequence of patches, each one doing only one thing. This will make it easier to review the patches to ensure that they are correct, and to help alleviate any merge issues that larger patches can cause.

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

#3 lore raw
In reply to Joash Naidoo
Quoted 3 lines · Joash Naidoo

Coding style fix. Fix too many leading tabs and line length. Convert __constant_htons to htons

Convert the __constant_htons to htons in a separate patch from reversing the if statements.

Quoted 51 lines
---
 drivers/staging/r8188eu/core/rtw_br_ext.c | 66 ++++++++++++-----------
 1 file changed, 35 insertions(+), 31 deletions(-)
drivers/staging/r8188eu/core/rtw_br_ext.c +7 -31
index bca20fe5c..8e951fc0e 100644
@@ -604,37 +604,41 @@ void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
 	if (!skb)
 		return;
 
-	if (!priv->ethBrExtInfo.dhcp_bcst_disable) {
-		__be16 protocol = *((__be16 *)(skb->data + 2 * ETH_ALEN));
-
-		if (protocol == __constant_htons(ETH_P_IP)) { /*  IP */
-			struct iphdr *iph = (struct iphdr *)(skb->data + ETH_HLEN);
-
-			if (iph->protocol == IPPROTO_UDP) { /*  UDP */
-				struct udphdr *udph = (struct udphdr *)((size_t)iph + (iph->ihl << 2));
-
-				if ((udph->source == __constant_htons(CLIENT_PORT)) &&
-				    (udph->dest == __constant_htons(SERVER_PORT))) { /*  DHCP request */
-					struct dhcpMessage *dhcph =
-						(struct dhcpMessage *)((size_t)udph + sizeof(struct udphdr));
-					u32 cookie = be32_to_cpu((__be32)dhcph->cookie);
-
-					if (cookie == DHCP_MAGIC) { /*  match magic word */
-						if (!(dhcph->flags & htons(BROADCAST_FLAG))) {
-							/*  if not broadcast */
-							register int sum = 0;
-
-							/*  or BROADCAST flag */
-							dhcph->flags |= htons(BROADCAST_FLAG);
-							/*  recalculate checksum */
-							sum = ~(udph->check) & 0xffff;
-							sum += be16_to_cpu(dhcph->flags);
-							while (sum >> 16)
-								sum = (sum & 0xffff) + (sum >> 16);
-							udph->check = ~sum;
-						}
-					}
-				}
+	if (priv->ethBrExtInfo.dhcp_bcst_disable)
+		return;
+
+	__be16 protocol = *((__be16 *)(skb->data + 2 * ETH_ALEN));
+
+	if (protocol != htons(ETH_P_IP)) /*  IP */
+		return;

drivers/staging/r8188eu/core/rtw_br_ext.c void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb) · line 623

Quoted 10 lines
drivers/staging/r8188eu/core/rtw_br_ext.c +10 -0
+
+	struct iphdr *iph = (struct iphdr *)(skb->data + ETH_HLEN);
+
+	if (iph->protocol != IPPROTO_UDP) /*  UDP */
+		return;
+
+	struct udphdr *udph = (struct udphdr *)((size_t)iph + (iph->ihl << 2));
+
+	if ((udph->source == htons(CLIENT_PORT)) &&
+	    (udph->dest == htons(SERVER_PORT))) { /*  DHCP request */

Flip this condition around as well. The anti-pattern here is "Don't reverse the last if statement."

	/* DHCP request */
	if ((udph->source != __constant_htons(CLIENT_PORT)) ||
	    (udph->dest != __constant_htons(SERVER_PORT)))
		return;

drivers/staging/r8188eu/core/rtw_br_ext.c void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb) · line 627

Quoted 4 lines
drivers/staging/r8188eu/core/rtw_br_ext.c +4 -0
+		struct dhcpMessage *dhcph =
+			(struct dhcpMessage *)((size_t)udph +
+						   sizeof(struct udphdr));
+		u32 cookie = be32_to_cpu((__be32)dhcph->cookie);

You'll have to move these declarations up the to start of the function which is fine.

drivers/staging/r8188eu/core/rtw_br_ext.c void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb) · line 629

Quoted 2 lines
drivers/staging/r8188eu/core/rtw_br_ext.c +2 -0
+
+		if (cookie == DHCP_MAGIC) { /*  match magic word */

Flip this as well.

	if (cookie != DHCP_MAGIC)
		return;

regards,
dan carpenter