Skip to contentSkip to conversation

staging: r8188eu: fix too many leading tabs

PATCH Superseded Joash Naidoo 2 participants 2 messages Sep 19, 2022 Staging

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

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

Coding style fix. Fix too many leading tabs and line length.

---
Changes in v2:
- Flip additional nested if conditions and don't reverse the last if statement
- Move declarations to start of function
- Separate converting __constant_htons to htons to another patch

---
 drivers/staging/r8188eu/core/rtw_br_ext.c | 69 ++++++++++++-----------
 1 file changed, 36 insertions(+), 33 deletions(-)
drivers/staging/r8188eu/core/rtw_br_ext.c +36 -33
index bca20fe5c..2fec3bf39 100644
@@ -601,42 +601,45 @@ struct dhcpMessage {
 
 void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
 {
+	__be16 protocol = *((__be16 *)(skb->data + 2 * ETH_ALEN));
+	struct iphdr *iph = (struct iphdr *)(skb->data + ETH_HLEN);
+	struct udphdr *udph = (struct udphdr *)((size_t)iph + (iph->ihl << 2));
+	/*  DHCP request */
+	struct dhcpMessage *dhcph =
+		(struct dhcpMessage *)((size_t)udph + sizeof(struct udphdr));
+	u32 cookie = be32_to_cpu((__be32)dhcph->cookie);
+
 	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;
+
+	if (protocol != htons(ETH_P_IP)) /*  IP */
+		return;
+
+	if (iph->protocol != IPPROTO_UDP) /*  UDP */
+		return;
+
+	if ((udph->source != __constant_htons(CLIENT_PORT)) &&
+	    (udph->dest != __constant_htons(SERVER_PORT)))
+		return;
+
+	if (cookie != DHCP_MAGIC) /*  match magic word */
+		return;
+
+	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 17 lines · Joash Naidoo

Coding style fix. Fix too many leading tabs and line length.

---
Changes in v2:
- Flip additional nested if conditions and don't reverse the last if statement
- Move declarations to start of function
- Separate converting __constant_htons to htons to another patch

---
 drivers/staging/r8188eu/core/rtw_br_ext.c | 69 ++++++++++++-----------
 1 file changed, 36 insertions(+), 33 deletions(-)
drivers/staging/r8188eu/core/rtw_br_ext.c +0 -0
index bca20fe5c..2fec3bf39 100644

drivers/staging/r8188eu/core/rtw_br_ext.c struct dhcpMessage { · line 604

Quoted 4 lines
drivers/staging/r8188eu/core/rtw_br_ext.c +1 -0
@@ -601,42 +601,45 @@ struct dhcpMessage {
 
 void dhcp_flag_bcast(struct adapter *priv, struct sk_buff *skb)
 {
+	__be16 protocol = *((__be16 *)(skb->data + 2 * ETH_ALEN));
                                       ^^^^^^^^^

Dereferencing skb before it has been NULL checked. Also do we really know how large the skb is? We seem to making a lot of assumptions...

drivers/staging/r8188eu/core/rtw_br_ext.c struct dhcpMessage { · line 612

Quoted 8 lines
drivers/staging/r8188eu/core/rtw_br_ext.c +7 -0
+	struct iphdr *iph = (struct iphdr *)(skb->data + ETH_HLEN);
+	struct udphdr *udph = (struct udphdr *)((size_t)iph + (iph->ihl << 2));
+	/*  DHCP request */
+	struct dhcpMessage *dhcph =
+		(struct dhcpMessage *)((size_t)udph + sizeof(struct udphdr));
+	u32 cookie = be32_to_cpu((__be32)dhcph->cookie);
+
 	if (!skb)
            ^^^^

Checked too late.

Quoted 2 lines
drivers/staging/r8188eu/core/rtw_br_ext.c +0 -0
 		return;
 

[ snip ]

drivers/staging/r8188eu/core/rtw_br_ext.c struct dhcpMessage { · line 625

Quoted 5 lines
drivers/staging/r8188eu/core/rtw_br_ext.c +5 -0
+	if (iph->protocol != IPPROTO_UDP) /*  UDP */
+		return;
+
+	if ((udph->source != __constant_htons(CLIENT_PORT)) &&
+	    (udph->dest != __constant_htons(SERVER_PORT)))

The && needs to be changed to ||.

drivers/staging/r8188eu/core/rtw_br_ext.c

Quoted 2 lines
drivers/staging/r8188eu/core/rtw_br_ext.c +2 -0
+		return;
+

regards,
dan carpenter