netfilter: bpf_link: avoid unused-function warning

Message ID 20230801150304.1980987-1-arnd@kernel.org
State New
Headers
Series netfilter: bpf_link: avoid unused-function warning |

Commit Message

Arnd Bergmann Aug. 1, 2023, 3:02 p.m. UTC
  From: Arnd Bergmann <arnd@arndb.de>

The newly added function is unused in some random configurations:

net/netfilter/nf_bpf_link.c:32:1: error: 'get_proto_defrag_hook' defined but not used [-Werror=unused-function]
   32 | get_proto_defrag_hook(struct bpf_nf_link *link,
      | ^~~~~~~~~~~~~~~~~~~~~

Change the preprocessor conditionals to if() checks that the
compiler can understand to avoid the warning.

Fixes: 91721c2d02d3a ("netfilter: bpf: Support BPF_F_NETFILTER_IP_DEFRAG in netfilter link")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 net/netfilter/nf_bpf_link.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
  

Comments

Daniel Xu Aug. 1, 2023, 3:20 p.m. UTC | #1
Hi Arnd,

On Tue, Aug 01, 2023 at 05:02:41PM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> The newly added function is unused in some random configurations:
> 
> net/netfilter/nf_bpf_link.c:32:1: error: 'get_proto_defrag_hook' defined but not used [-Werror=unused-function]
>    32 | get_proto_defrag_hook(struct bpf_nf_link *link,
>       | ^~~~~~~~~~~~~~~~~~~~~
> 

This was fixed in 81584c23f249 ("netfilter: bpf: Only define get_proto_defrag_hook() if necessary").

Thanks,
Daniel
  
Arnd Bergmann Aug. 1, 2023, 5:27 p.m. UTC | #2
On Tue, Aug 1, 2023, at 17:20, Daniel Xu wrote:
> Hi Arnd,
>
> On Tue, Aug 01, 2023 at 05:02:41PM +0200, Arnd Bergmann wrote:
>> From: Arnd Bergmann <arnd@arndb.de>
>> 
>> The newly added function is unused in some random configurations:
>> 
>> net/netfilter/nf_bpf_link.c:32:1: error: 'get_proto_defrag_hook' defined but not used [-Werror=unused-function]
>>    32 | get_proto_defrag_hook(struct bpf_nf_link *link,
>>       | ^~~~~~~~~~~~~~~~~~~~~
>> 
>
> This was fixed in 81584c23f249 ("netfilter: bpf: Only define 
> get_proto_defrag_hook() if necessary").

Ok, I guess this will be in tomorrow's linux-next then, right?

    Arnd
  
Daniel Xu Aug. 1, 2023, 7:29 p.m. UTC | #3
On Tue, Aug 01, 2023 at 07:27:33PM +0200, Arnd Bergmann wrote:
> On Tue, Aug 1, 2023, at 17:20, Daniel Xu wrote:
> > Hi Arnd,
> >
> > On Tue, Aug 01, 2023 at 05:02:41PM +0200, Arnd Bergmann wrote:
> >> From: Arnd Bergmann <arnd@arndb.de>
> >> 
> >> The newly added function is unused in some random configurations:
> >> 
> >> net/netfilter/nf_bpf_link.c:32:1: error: 'get_proto_defrag_hook' defined but not used [-Werror=unused-function]
> >>    32 | get_proto_defrag_hook(struct bpf_nf_link *link,
> >>       | ^~~~~~~~~~~~~~~~~~~~~
> >> 
> >
> > This was fixed in 81584c23f249 ("netfilter: bpf: Only define 
> > get_proto_defrag_hook() if necessary").
> 
> Ok, I guess this will be in tomorrow's linux-next then, right?
> 
>     Arnd

I'm not too familiar with the linux-next process, but chatgpt is telling
me it should be.

Thanks,
Daniel
  

Patch

diff --git a/net/netfilter/nf_bpf_link.c b/net/netfilter/nf_bpf_link.c
index 8fe594bbc7e24..6028fd4c1ab4c 100644
--- a/net/netfilter/nf_bpf_link.c
+++ b/net/netfilter/nf_bpf_link.c
@@ -74,24 +74,26 @@  static int bpf_nf_enable_defrag(struct bpf_nf_link *link)
 	const struct nf_defrag_hook __maybe_unused *hook;
 
 	switch (link->hook_ops.pf) {
-#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4)
 	case NFPROTO_IPV4:
+		if (!IS_ENABLED(CONFIG_NF_DEFRAG_IPV4))
+			return -EAFNOSUPPORT;
+
 		hook = get_proto_defrag_hook(link, nf_defrag_v4_hook, "nf_defrag_ipv4");
 		if (IS_ERR(hook))
 			return PTR_ERR(hook);
 
 		link->defrag_hook = hook;
 		return 0;
-#endif
-#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
 	case NFPROTO_IPV6:
+		if (!IS_ENABLED(CONFIG_NF_DEFRAG_IPV6))
+			return -EAFNOSUPPORT;
+
 		hook = get_proto_defrag_hook(link, nf_defrag_v6_hook, "nf_defrag_ipv6");
 		if (IS_ERR(hook))
 			return PTR_ERR(hook);
 
 		link->defrag_hook = hook;
 		return 0;
-#endif
 	default:
 		return -EAFNOSUPPORT;
 	}