diff mbox series

[net-next,1/2] net/tcp: fix -Wshadow / Sparse shadow warnings in tcp_hash_fail()

Message ID 20240329170000.3241460-2-aleksander.lobakin@intel.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: fix variable shadowing spam from headers | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1847 this patch: 1847
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 5 maintainers not CCed: justinstitt@google.com ndesaulniers@google.com llvm@lists.linux.dev morbo@google.com nathan@kernel.org
netdev/build_clang success Errors and warnings before: 974 this patch: 974
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1883 this patch: 1883
netdev/checkpatch warning CHECK: Macro argument 'th' may be better as '(th)' to avoid precedence issues WARNING: A patch subject line should describe the change not the tool that found it
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Alexander Lobakin March 29, 2024, 4:59 p.m. UTC
Fix the following spam coming from <net/tcp_ao.h> when building with
W=12 and/or C=1:

Clang:

In file included from drivers/net/ethernet/intel/idpf/idpf_txrx.c:4:
In file included from drivers/net/ethernet/intel/idpf/idpf.h:24:
In file included from drivers/net/ethernet/intel/idpf/idpf_txrx.h:8:
./include/net/tcp.h:2812:3: warning: declaration shadows a local variable [-Wshadow]
 2812 |                 tcp_hash_fail("TCP segment has incorrect auth options set",
      |                 ^
./include/net/tcp_ao.h:153:23: note: expanded from macro 'tcp_hash_fail'
  153 |         const struct tcphdr *th = tcp_hdr(skb);                         \
      |                              ^
./include/net/tcp.h:2805:23: note: previous declaration is here
 2805 |         const struct tcphdr *th = tcp_hdr(skb);
      |                              ^
./include/net/tcp.h:2820:4: warning: declaration shadows a local variable [-Wshadow]
 2820 |                         tcp_hash_fail("TCP connection can't start/end using TCP-AO",
      |                         ^
./include/net/tcp_ao.h:153:23: note: expanded from macro 'tcp_hash_fail'
  153 |         const struct tcphdr *th = tcp_hdr(skb);                         \
      |                              ^
./include/net/tcp.h:2805:23: note: previous declaration is here
 2805 |         const struct tcphdr *th = tcp_hdr(skb);
      |                              ^
./include/net/tcp.h:2840:4: warning: declaration shadows a local variable [-Wshadow]
 2840 |                         tcp_hash_fail("AO hash is required, but not found",
      |                         ^
./include/net/tcp_ao.h:153:23: note: expanded from macro 'tcp_hash_fail'
  153 |         const struct tcphdr *th = tcp_hdr(skb);                         \
      |                              ^
./include/net/tcp.h:2805:23: note: previous declaration is here
 2805 |         const struct tcphdr *th = tcp_hdr(skb);
      |                              ^
./include/net/tcp.h:2846:4: warning: declaration shadows a local variable [-Wshadow]

Sparse:

drivers/net/ethernet/intel/idpf/idpf_main.c: note: in included file (through drivers/net/ethernet/intel/idpf/idpf_txrx.h, drivers/net/ethernet/intel/idpf/idpf.h):
./include/net/tcp.h:2812:17: warning: symbol 'th' shadows an earlier one
./include/net/tcp.h:2805:29: originally declared here
./include/net/tcp.h:2820:25: warning: symbol 'th' shadows an earlier one
./include/net/tcp.h:2805:29: originally declared here
./include/net/tcp.h:2840:25: warning: symbol 'th' shadows an earlier one
./include/net/tcp.h:2805:29: originally declared here
./include/net/tcp.h:2846:25: warning: symbol 'th' shadows an earlier one
./include/net/tcp.h:2805:29: originally declared here

Just use __UNIQUE_ID() for the variables declared inside
tcp_hash_fail().

Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
---
 include/net/tcp_ao.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/include/net/tcp_ao.h b/include/net/tcp_ao.h
index 471e177362b4..c5303c9c6f80 100644
--- a/include/net/tcp_ao.h
+++ b/include/net/tcp_ao.h
@@ -148,7 +148,7 @@  static inline bool tcp_hash_should_produce_warnings(void)
 	return static_branch_tcp_md5() || static_branch_tcp_ao();
 }
 
-#define tcp_hash_fail(msg, family, skb, fmt, ...)			\
+#define _tcp_hash_fail(msg, family, skb, th, hdr_flags, f, fmt, ...)	\
 do {									\
 	const struct tcphdr *th = tcp_hdr(skb);				\
 	char hdr_flags[6];						\
@@ -179,6 +179,10 @@  do {									\
 				hdr_flags, ##__VA_ARGS__);		\
 	}								\
 } while (0)
+#define tcp_hash_fail(msg, family, skb, fmt, ...)			\
+	_tcp_hash_fail(msg, family, skb, __UNIQUE_ID(th_),		\
+		       __UNIQUE_ID(hdr_flags_), __UNIQUE_ID(f_), fmt,	\
+		       ##__VA_ARGS__)
 
 #ifdef CONFIG_TCP_AO
 /* TCP-AO structures and functions */