pktgen: avoid unused-const-variable warning
Subsystems (2)
PATCH 1/1 pktgen: avoid unused-const-variable warning
From: Arnd Bergmann <[email protected]>
When extra warnings are enable, there are configurations that build pktgen without CONFIG_XFRM, which leaves a static const variable unused:
net/core/pktgen.c:213:1: error: unused variable 'F_IPSEC' [-Werror,-Wunused-const-variable]
213 | PKT_FLAGS
| ^~~~~~~~~
net/core/pktgen.c:197:2: note: expanded from macro 'PKT_FLAGS'
197 | pf(IPSEC) /* ipsec on for flows */ \
| ^~~~~~~~~This could be marked as __maybe_unused, or by making the one use visible to the compiler by slightly rearranging the #ifdef blocks. The second variant looks slightly nicer here, so use that.
--- net/core/pktgen.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
net/core/pktgen.c +2 -7
@@ -158,9 +158,7 @@#include <net/udp.h> #include <net/ip6_checksum.h> #include <net/addrconf.h> -#ifdef CONFIG_XFRM #include <net/xfrm.h> -#endif #include <net/netns/generic.h> #include <asm/byteorder.h> #include <linux/rcupdate.h>
@@ -2363,13 +2361,13 @@ static inline int f_pick(struct pktgen_dev *pkt_dev) } -#ifdef CONFIG_XFRM /* If there was already an IPSEC SA, we keep it as is, else * we go look for it ... */ #define DUMMY_MARK 0static void get_ipsec_sa (struct pktgen_dev *pkt_dev,int flow) { +#ifdef CONFIG_XFRM struct xfrm_state *x = pkt_dev->flows[flow].x;struct pktgen_net *pn =net_generic (dev_net (pkt_dev->odev), pg_net_id);if (!x) {
@@ -2395,11 +2393,10 @@ static void get_ipsec_sa(struct pktgen_dev *pkt_dev, int flow) } } -}#endif +}static void set_cur_queue_map (struct pktgen_dev *pkt_dev) { -if (pkt_dev->flags &F_QUEUE_MAP_CPU ) pkt_dev->cur_queue_map =smp_processor_id ();
@@ -2574,10 +2571,8 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev) pkt_dev->flows[flow].flags |=F_INIT ; pkt_dev->flows[flow].cur_daddr = pkt_dev->cur_daddr; -#ifdef CONFIG_XFRM if (pkt_dev->flags &F_IPSEC )get_ipsec_sa (pkt_dev, flow); -#endif pkt_dev->nflows++; } }
Signature · 1 line
2.39.5
Hello Arnd,
Quoted 26 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
When extra warnings are enable, there are configurations that build pktgen without
CONFIG_XFRM, which leaves a static const variable unused:
net/core/pktgen.c:213:1: error: unused variable 'F_IPSEC' [-Werror,-Wunused-const-variable]
213 |PKT_FLAGS| ^~~~~~~~~ net/core/pktgen.c:197:2: note: expanded from macro 'PKT_FLAGS' 197 | pf(IPSEC) /* ipsec on for flows */ \ | ^~~~~~~~~This could be marked as
__maybe_unused, or by making the one use visible to the compiler by slightly rearranging the #ifdef blocks. The second variant looks slightly nicer here, so use that.Signed-off-by Arnd Bergmann <[email protected]>--- net/core/pktgen.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)net/core/pktgen.c +0
-0
net/core/pktgen.c line 163
Quoted 6 lines
net/core/pktgen.c +0
-2@@ -158,9 +158,7 @@#include <net/udp.h> #include <net/ip6_checksum.h> #include <net/addrconf.h> -#ifdef CONFIG_XFRM #include <net/xfrm.h> -#endif
This ifdef/endif can be kept (as the xfrm stuff is still not used)...
net/core/pktgen.c static inline int f_pick(struct pktgen_dev *pkt_dev) · line 2367
Quoted 12 lines
net/core/pktgen.c +0
-1#include <net/netns/generic.h> #include <asm/byteorder.h> #include <linux/rcupdate.h> @@ -2363,13 +2361,13 @@ static inline int f_pick(struct pktgen_dev *pkt_dev) } -#ifdef CONFIG_XFRM /* If there was already an IPSEC SA, we keep it as is, else * we go look for it ... */ #define DUMMY_MARK 0
A now unused define...
net/core/pktgen.c static inline int f_pick(struct pktgen_dev *pkt_dev) · line 2372
Quoted 5 lines
net/core/pktgen.c +1
-0static void get_ipsec_sa (struct pktgen_dev *pkt_dev,int flow) { +#ifdef CONFIG_XFRM struct xfrm_state *x = pkt_dev->flows[flow].x;struct pktgen_net *pn =net_generic (dev_net (pkt_dev->odev), pg_net_id);
Maybe better this way here?
const u32 dummy_mark = 0;
Quoted 15 lines
net/core/pktgen.c +1
-2if (!x) {@@ -2395,11 +2393,10 @@ static void get_ipsec_sa(struct pktgen_dev *pkt_dev, int flow) } } -}#endif +}static void set_cur_queue_map (struct pktgen_dev *pkt_dev) { -if (pkt_dev->flags &F_QUEUE_MAP_CPU ) pkt_dev->cur_queue_map =smp_processor_id ();
net/core/pktgen.c static void mod_cur_headers(struct pktgen_dev *pkt_dev) · line 2578
Quoted 10 lines
net/core/pktgen.c +0
-2@@ -2574,10 +2571,8 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev) pkt_dev->flows[flow].flags |=F_INIT ; pkt_dev->flows[flow].cur_daddr = pkt_dev->cur_daddr; -#ifdef CONFIG_XFRM if (pkt_dev->flags &F_IPSEC )get_ipsec_sa (pkt_dev, flow); -#endif pkt_dev->nflows++; } }
Otherwise works as expected, you can add my (with or without the suggested changes)
Regards,
Peter
Paolo Abeni
maintainerQuoted 20 lines · Peter Seiderer
From: Arnd Bergmann <[email protected]>
Quoted 19 lines
When extra warnings are enable, there are configurations that build pktgen without
CONFIG_XFRM, which leaves a static const variable unused:
net/core/pktgen.c:213:1: error: unused variable 'F_IPSEC' [-Werror,-Wunused-const-variable]
213 |PKT_FLAGS| ^~~~~~~~~ net/core/pktgen.c:197:2: note: expanded from macro 'PKT_FLAGS' 197 | pf(IPSEC) /* ipsec on for flows */ \ | ^~~~~~~~~This could be marked as
__maybe_unused, or by making the one use visible to the compiler by slightly rearranging the #ifdef blocks. The second variant looks slightly nicer here, so use that.Signed-off-by Arnd Bergmann <[email protected]>--- net/core/pktgen.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
Quoted 13 lines
net/core/pktgen.c line 163
Quoted 11 lines
net/core/pktgen.c +0
-2@@ -158,9 +158,7 @@#include <net/udp.h> #include <net/ip6_checksum.h> #include <net/addrconf.h> -#ifdef CONFIG_XFRM #include <net/xfrm.h> -#endif This ifdef/endif can be kept (as the xfrm stuff is still not used)...
FTR, I think dropping unneeded #ifdef is preferable in c files: only such file build time is affected, and the code is more readable.
Quoted 16 lines
net/core/pktgen.c static inline int f_pick(struct pktgen_dev *pkt_dev) · line 2367
Quoted 13 lines
net/core/pktgen.c +0
-1#include <net/netns/generic.h> #include <asm/byteorder.h> #include <linux/rcupdate.h> @@ -2363,13 +2361,13 @@ static inline int f_pick(struct pktgen_dev *pkt_dev) } -#ifdef CONFIG_XFRM /* If there was already an IPSEC SA, we keep it as is, else * we go look for it ... */ #define DUMMY_MARK 0A now unused define...
Quoted 7 lines
net/core/pktgen.c static inline int f_pick(struct pktgen_dev *pkt_dev) · line 2372
Quoted 5 lines
net/core/pktgen.c +1
-0static void get_ipsec_sa (struct pktgen_dev *pkt_dev,int flow) { +#ifdef CONFIG_XFRM struct xfrm_state *x = pkt_dev->flows[flow].x;struct pktgen_net *pn =net_generic (dev_net (pkt_dev->odev), pg_net_id);Maybe better this way here?
I think the unused define is preferable; I think pre-processor defines are cheaper than static const.
Thanks,
Paolo
Hello Paolo,
Quoted 35 lines · Paolo Abeni
Quoted 20 lines · Peter Seiderer
From: Arnd Bergmann <[email protected]>
Quoted 19 lines
When extra warnings are enable, there are configurations that build pktgen without
CONFIG_XFRM, which leaves a static const variable unused:
net/core/pktgen.c:213:1: error: unused variable 'F_IPSEC' [-Werror,-Wunused-const-variable]
213 |PKT_FLAGS| ^~~~~~~~~ net/core/pktgen.c:197:2: note: expanded from macro 'PKT_FLAGS' 197 | pf(IPSEC) /* ipsec on for flows */ \ | ^~~~~~~~~This could be marked as
__maybe_unused, or by making the one use visible to the compiler by slightly rearranging the #ifdef blocks. The second variant looks slightly nicer here, so use that.Signed-off-by Arnd Bergmann <[email protected]>--- net/core/pktgen.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)Quoted 13 lines
net/core/pktgen.c line 163
Quoted 11 lines
net/core/pktgen.c +0
-2@@ -158,9 +158,7 @@#include <net/udp.h> #include <net/ip6_checksum.h> #include <net/addrconf.h> -#ifdef CONFIG_XFRM #include <net/xfrm.h> -#endif This ifdef/endif can be kept (as the xfrm stuff is still not used)...
Quoted 2 lines
FTR, I think dropping unneeded #ifdef is preferable in c files: only such file build time is affected, and the code is more readable.
The ifdef/endif emphasizes no xfrm usage (even by mistake) in case CONFIG_XFRM is not defined, but in the end a matter of taste ;-)
Quoted 23 lines
Quoted 23 lines
Quoted 6 lines
net/core/pktgen.c +0
-0#include <net/netns/generic.h> #include <asm/byteorder.h> #include <linux/rcupdate.h> net/core/pktgen.c static inline int f_pick(struct pktgen_dev *pkt_dev) · line 2367
Quoted 8 lines
net/core/pktgen.c +0
-1@@ -2363,13 +2361,13 @@ static inline int f_pick(struct pktgen_dev *pkt_dev) } -#ifdef CONFIG_XFRM /* If there was already an IPSEC SA, we keep it as is, else * we go look for it ... */ #define DUMMY_MARK 0A now unused define...
Quoted 5 lines
net/core/pktgen.c +1
-0static void get_ipsec_sa (struct pktgen_dev *pkt_dev,int flow) { +#ifdef CONFIG_XFRM struct xfrm_state *x = pkt_dev->flows[flow].x;struct pktgen_net *pn =net_generic (dev_net (pkt_dev->odev), pg_net_id);
Quoted 6 lines
Quoted 3 lines
Maybe better this way here?
const u32 dummy_mark = 0;I think the unused define is preferable; I think pre-processor defines are cheaper than static const.
In which regards cheaper (out of interest)?
Both (with and without static) produce the same code see e.g.
https://godbolt.org/z/Tsr1jM45r https://godbolt.org/z/6sr1o8da3
Regards,
Peter
Quoted 5 lines
Thanks,
Paolo
Paolo Abeni
maintainerQuoted 10 lines · Peter Seiderer
Quoted 2 lines · Paolo Abeni
I think the unused define is preferable; I think pre-processor defines are cheaper than static const.
In which regards cheaper (out of interest)?
Both (with and without static) produce the same code see e.g.
https://godbolt.org/z/Tsr1jM45r https://godbolt.org/z/6sr1o8da3
I must admit I was unsure the compiler would always optimize out the constant.
I guess the macro could still produce shorter build time (by a few clock cycles, nothing measurable ;), so in the end it boils down again to a personal preference.
Cheers,
Paolo
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 5 lines · On Tue, 25 Feb 2025 09:57:14 +0100 you wrote:
From: Arnd Bergmann <[email protected]>
When extra warnings are enable, there are configurations that build pktgen without
CONFIG_XFRM, which leaves a static const variable unused:
Quoted 8 lines
net/core/pktgen.c:213:1: error: unused variable 'F_IPSEC' [-Werror,-Wunused-const-variable]
213 |PKT_FLAGS| ^~~~~~~~~ net/core/pktgen.c:197:2: note: expanded from macro 'PKT_FLAGS' 197 | pf(IPSEC) /* ipsec on for flows */ \ | ^~~~~~~~~[...]
Here is the summary with links:
- pktgen: avoid unused-const-variable warning
https://git.kernel.org/netdev/net-next/c/af4a5da8ed54
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html