net: Address some issues reported by Smatch
Subsystems (2)
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]>
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
@@ -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
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.Signed-off-by Andrew Goodbody <[email protected]>--- include/net/tcp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/net/tcp.h +0
-0
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
PATCH 2/3 net: Incorrect NOP macro used for test
In reply to Andrew GoodbodyIn 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
@@ -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
Re: [PATCH 2/3] net: Incorrect NOP macro used for test
Quoted 17 lines · Andrew Goodbody
In
tcp_parse_optionsthe uchar p[0] is attempted to test for a match with the 32bit macroTCP_0_NOPwhich can never be true. Instead test against the 8bit macroTCP_1_NOP.This issue found by Smatch.
Signed-off-by Andrew Goodbody <[email protected]>--- net/tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/tcp.c +0
-0
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
PATCH 3/3 net: wget: Fix comparison of unsigned variable
In reply to Andrew Goodbodycontent_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
@@ -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
Re: [PATCH 3/3] net: wget: Fix comparison of unsigned variable
Quoted 17 lines · Andrew Goodbody
content_lengthis 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.
Signed-off-by Andrew Goodbody <[email protected]>--- net/wget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/wget.c +0
-0
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