Skip to contentSkip to conversation

net: Address some issues reported by Smatch

PATCH In review Andrew Goodbody 2 participants 7 messages Jul 8, 2025 – Jul 9, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover net: Address some issues reported by Smatch

Smatch reported some issues including a macro that was missing outer parens, a comparison of an 8bit type against a 32bit define and a comparison that was always true due to being an unsigned type.

---
Andrew Goodbody (3):
net: Add parens to macro PSEUDO_HDR_SIZE
net: Incorrect NOP macro used for test
net: wget: Fix comparison of unsigned variable

 include/net/tcp.h | 2 +-
 net/tcp.c         | 2 +-
 net/wget.c        | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

---
base-commit: d1d53c252a4a746db5ebcdf0d6de3aa0feec504e
change-id: 20250708-net_fix-784f5ac63756

Best regards,

Signature · 1 line
Andrew Goodbody <[email protected]>
#1 lore raw

PATCH 1/3 net: Add parens to macro PSEUDO_HDR_SIZE

Smatch reports a warning about possibly needing parens around the macro PSEUDO_HDR_SIZE. This will not affect the one place the macro is used but add the parens anyway as it is good practice to have them and if the macro is used again in the future it could possibly matter then.

---
 include/net/tcp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/tcp.h +1 -1
index 5022fa9dc1b..6f4d58a1234 100644
@@ -235,7 +235,7 @@ struct pseudo_hdr {
 	u16     len;
 } __packed;
 
-#define PSEUDO_HDR_SIZE	(sizeof(struct pseudo_hdr)) - PSEUDO_PAD_SIZE
+#define PSEUDO_HDR_SIZE	((sizeof(struct pseudo_hdr)) - PSEUDO_PAD_SIZE)
 
 /**
  * union tcp_build_pkt - union for building TCP/IP packet.
Signature · 1 line
2.39.5
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] net: Add parens to macro PSEUDO_HDR_SIZE

Quoted 16 lines · Andrew Goodbody

Smatch reports a warning about possibly needing parens around the macro PSEUDO_HDR_SIZE. This will not affect the one place the macro is used but add the parens anyway as it is good practice to have them and if the macro is used again in the future it could possibly matter then.

---
 include/net/tcp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/tcp.h +0 -0
index 5022fa9dc1b..6f4d58a1234 100644

include/net/tcp.h struct pseudo_hdr { · line 241

Quoted 8 lines
include/net/tcp.h +1 -1
@@ -235,7 +235,7 @@ struct pseudo_hdr {
 	u16     len;
 } __packed;
 
-#define PSEUDO_HDR_SIZE	(sizeof(struct pseudo_hdr)) - PSEUDO_PAD_SIZE
+#define PSEUDO_HDR_SIZE	((sizeof(struct pseudo_hdr)) - PSEUDO_PAD_SIZE)
 
 /**
  * union tcp_build_pkt - union for building TCP/IP packet.

Thanks,

Signature · 1 line
Jerome
#3 lore raw

PATCH 2/3 net: Incorrect NOP macro used for test

In reply to Andrew Goodbody

In tcp_parse_options the uchar p[0] is attempted to test for a match with the 32bit macro TCP_0_NOP which can never be true. Instead test against the 8bit macro TCP_1_NOP.

This issue found by Smatch.

---
 net/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/tcp.c +1 -1
index 2635727f47d..8740150365f 100644
@@ -804,7 +804,7 @@ void tcp_parse_options(struct tcp_stream *tcp, uchar *o, int o_len)
 		}
 
 		/* Process optional NOPs */
-		if (p[0] == TCP_O_NOP)
+		if (p[0] == TCP_1_NOP)
 			p++;
 		else
 			p += p[1];
Signature · 1 line
2.39.5
Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] net: Incorrect NOP macro used for test

Quoted 17 lines · Andrew Goodbody

In tcp_parse_options the uchar p[0] is attempted to test for a match with the 32bit macro TCP_0_NOP which can never be true. Instead test against the 8bit macro TCP_1_NOP.

This issue found by Smatch.

---
 net/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/tcp.c +0 -0
index 2635727f47d..8740150365f 100644

net/tcp.c void tcp_parse_options(struct tcp_stream *tcp, uchar *o, int o_len) · line 810

Quoted 8 lines
net/tcp.c +1 -1
@@ -804,7 +804,7 @@ void tcp_parse_options(struct tcp_stream *tcp, uchar *o, int o_len)
 		}
 
 		/* Process optional NOPs */
-		if (p[0] == TCP_O_NOP)
+		if (p[0] == TCP_1_NOP)
 			p++;
 		else
 			p += p[1];

Thanks,

Signature · 1 line
Jerome
#5 lore raw

PATCH 3/3 net: wget: Fix comparison of unsigned variable

In reply to Andrew Goodbody

content_length is an unsigned long and so testing that it is >= 0 will always be true. Instead test that it is != -1 as that is the condition set on error.

This issue found by Smatch.

---
 net/wget.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/wget.c +1 -1
index 3c0fff488eb..428ee072330 100644
@@ -214,7 +214,7 @@ static void tcp_stream_on_rcv_nxt_update(struct tcp_stream *tcp, u32 rx_bytes)
 			content_length = -1;
 	}
 
-	if (content_length >= 0) {
+	if (content_length != -1) {
 		debug_cond(DEBUG_WGET,
 			   "wget: Connected Len %lu\n",
 			   content_length);
Signature · 1 line
2.39.5
Reviewed-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] net: wget: Fix comparison of unsigned variable

Quoted 17 lines · Andrew Goodbody

content_length is an unsigned long and so testing that it is >= 0 will always be true. Instead test that it is != -1 as that is the condition set on error.

This issue found by Smatch.

---
 net/wget.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/wget.c +0 -0
index 3c0fff488eb..428ee072330 100644

net/wget.c static void tcp_stream_on_rcv_nxt_update(struct tcp_stream *tcp, u32 rx_bytes) · line 220

Quoted 8 lines
net/wget.c +1 -1
@@ -214,7 +214,7 @@ static void tcp_stream_on_rcv_nxt_update(struct tcp_stream *tcp, u32 rx_bytes)
 			content_length = -1;
 	}
 
-	if (content_length >= 0) {
+	if (content_length != -1) {
 		debug_cond(DEBUG_WGET,
 			   "wget: Connected Len %lu\n",
 			   content_length);

Thanks,

Signature · 1 line
Jerome