* [PATCH] netfilter: amanda: fix RCU pointer typing for nf_nat_amanda_hook
@ 2026-02-03 8:01 Sun Jian
2026-02-03 13:50 ` Florian Westphal
2026-02-03 14:55 ` [PATCH v2] " Sun Jian
0 siblings, 2 replies; 11+ messages in thread
From: Sun Jian @ 2026-02-03 8:01 UTC (permalink / raw)
To: Pablo Neira Ayuso, Florian Westphal
Cc: Phil Sutter, Simon Horman, netfilter-devel, netdev, linux-kernel,
Sun Jian
The nf_nat_amanda_hook pointer is accessed via rcu_dereference(), but
it lacks the __rcu annotation in its declaration and definition. Sparse
reports "incompatible types in comparison expression (different
address spaces)" errors in nf_conntrack_amanda.c.
Fix this by:
1. Adding __rcu and __read_mostly to the global nf_nat_amanda_hook
declaration.
2. Adding __rcu to the global nf_nat_amanda_hook definition.
3. Explicitly declaring the local nf_nat_amanda function pointer
without __rcu to store the dereferenced pointer.
4. Using rcu_dereference_raw() to fetch the hook address, which
satisfies sparse's type checking for function pointers.
Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
---
include/linux/netfilter/nf_conntrack_amanda.h | 3 ++-
net/netfilter/nf_conntrack_amanda.c | 11 ++++++++---
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/include/linux/netfilter/nf_conntrack_amanda.h b/include/linux/netfilter/nf_conntrack_amanda.h
index 6f0ac896fcc9..edf1d30135a3 100644
--- a/include/linux/netfilter/nf_conntrack_amanda.h
+++ b/include/linux/netfilter/nf_conntrack_amanda.h
@@ -12,5 +12,6 @@ extern unsigned int (*nf_nat_amanda_hook)(struct sk_buff *skb,
unsigned int protoff,
unsigned int matchoff,
unsigned int matchlen,
- struct nf_conntrack_expect *exp);
+ struct nf_conntrack_expect *exp)
+ __rcu __read_mostly;
#endif /* _NF_CONNTRACK_AMANDA_H */
diff --git a/net/netfilter/nf_conntrack_amanda.c b/net/netfilter/nf_conntrack_amanda.c
index 7be4c35e4795..7b3fffea45da 100644
--- a/net/netfilter/nf_conntrack_amanda.c
+++ b/net/netfilter/nf_conntrack_amanda.c
@@ -43,7 +43,7 @@ unsigned int (*nf_nat_amanda_hook)(struct sk_buff *skb,
unsigned int matchoff,
unsigned int matchlen,
struct nf_conntrack_expect *exp)
- __read_mostly;
+ __rcu __read_mostly;
EXPORT_SYMBOL_GPL(nf_nat_amanda_hook);
enum amanda_strings {
@@ -98,7 +98,12 @@ static int amanda_help(struct sk_buff *skb,
u_int16_t len;
__be16 port;
int ret = NF_ACCEPT;
- typeof(nf_nat_amanda_hook) nf_nat_amanda;
+ unsigned int (*nf_nat_amanda)(struct sk_buff *skb,
+ enum ip_conntrack_info ctinfo,
+ unsigned int protoff,
+ unsigned int matchoff,
+ unsigned int matchlen,
+ struct nf_conntrack_expect *exp);
/* Only look at packets from the Amanda server */
if (CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL)
@@ -155,7 +160,7 @@ static int amanda_help(struct sk_buff *skb,
&tuple->src.u3, &tuple->dst.u3,
IPPROTO_TCP, NULL, &port);
- nf_nat_amanda = rcu_dereference(nf_nat_amanda_hook);
+ nf_nat_amanda = rcu_dereference_raw(nf_nat_amanda_hook);
if (nf_nat_amanda && ct->status & IPS_NAT_MASK)
ret = nf_nat_amanda(skb, ctinfo, protoff,
off - dataoff, len, exp);
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH] netfilter: amanda: fix RCU pointer typing for nf_nat_amanda_hook
2026-02-03 8:01 [PATCH] netfilter: amanda: fix RCU pointer typing for nf_nat_amanda_hook Sun Jian
@ 2026-02-03 13:50 ` Florian Westphal
2026-02-03 14:36 ` sun jian
2026-02-03 14:55 ` [PATCH v2] " Sun Jian
1 sibling, 1 reply; 11+ messages in thread
From: Florian Westphal @ 2026-02-03 13:50 UTC (permalink / raw)
To: Sun Jian
Cc: Pablo Neira Ayuso, Phil Sutter, Simon Horman, netfilter-devel,
netdev, linux-kernel
Sun Jian <sun.jian.kdev@gmail.com> wrote:
> The nf_nat_amanda_hook pointer is accessed via rcu_dereference(), but
> it lacks the __rcu annotation in its declaration and definition. Sparse
> reports "incompatible types in comparison expression (different
> address spaces)" errors in nf_conntrack_amanda.c.
>
> Fix this by:
> 1. Adding __rcu and __read_mostly to the global nf_nat_amanda_hook
> declaration.
> 2. Adding __rcu to the global nf_nat_amanda_hook definition.
> 3. Explicitly declaring the local nf_nat_amanda function pointer
> without __rcu to store the dereferenced pointer.
> 4. Using rcu_dereference_raw() to fetch the hook address, which
> satisfies sparse's type checking for function pointers.
This doesn't look right, esp. step 4. Why not:
diff --git a/include/linux/netfilter/nf_conntrack_amanda.h b/include/linux/netfilter/nf_conntrack_amanda.h
--- a/include/linux/netfilter/nf_conntrack_amanda.h
+++ b/include/linux/netfilter/nf_conntrack_amanda.h
@@ -7,7 +7,7 @@
#include <linux/skbuff.h>
#include <net/netfilter/nf_conntrack_expect.h>
-extern unsigned int (*nf_nat_amanda_hook)(struct sk_buff *skb,
+extern unsigned int (__rcu *nf_nat_amanda_hook)(struct sk_buff *skb,
enum ip_conntrack_info ctinfo,
unsigned int protoff,
unsigned int matchoff,
diff --git a/net/netfilter/nf_conntrack_amanda.c b/net/netfilter/nf_conntrack_amanda.c
--- a/net/netfilter/nf_conntrack_amanda.c
+++ b/net/netfilter/nf_conntrack_amanda.c
@@ -37,7 +37,7 @@ MODULE_PARM_DESC(master_timeout, "timeout for the master connection");
module_param(ts_algo, charp, 0400);
MODULE_PARM_DESC(ts_algo, "textsearch algorithm to use (default kmp)");
-unsigned int (*nf_nat_amanda_hook)(struct sk_buff *skb,
+unsigned int (__rcu *nf_nat_amanda_hook)(struct sk_buff *skb,
enum ip_conntrack_info ctinfo,
unsigned int protoff,
unsigned int matchoff,
?
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] netfilter: amanda: fix RCU pointer typing for nf_nat_amanda_hook
2026-02-03 13:50 ` Florian Westphal
@ 2026-02-03 14:36 ` sun jian
0 siblings, 0 replies; 11+ messages in thread
From: sun jian @ 2026-02-03 14:36 UTC (permalink / raw)
To: Florian Westphal
Cc: Pablo Neira Ayuso, Phil Sutter, Simon Horman, netfilter-devel,
netdev, linux-kernel
On Tue, Feb 3, 2026 at 9:50 PM Florian Westphal <fw@strlen.de> wrote:
>
> Sun Jian <sun.jian.kdev@gmail.com> wrote:
> > 4. Using rcu_dereference_raw() to fetch the hook address, which
> > satisfies sparse's type checking for function pointers.
>
> This doesn't look right, esp. step 4. Why not:
>
> diff --git a/include/linux/netfilter/nf_conntrack_amanda.h b/include/linux/netfilter/nf_conntrack_amanda.h
> --- a/include/linux/netfilter/nf_conntrack_amanda.h
> +++ b/include/linux/netfilter/nf_conntrack_amanda.h
> @@ -7,7 +7,7 @@
> #include <linux/skbuff.h>
> #include <net/netfilter/nf_conntrack_expect.h>
>
> -extern unsigned int (*nf_nat_amanda_hook)(struct sk_buff *skb,
> +extern unsigned int (__rcu *nf_nat_amanda_hook)(struct sk_buff *skb,
> enum ip_conntrack_info ctinfo,
> unsigned int protoff,
> unsigned int matchoff,
> diff --git a/net/netfilter/nf_conntrack_amanda.c b/net/netfilter/nf_conntrack_amanda.c
> --- a/net/netfilter/nf_conntrack_amanda.c
> +++ b/net/netfilter/nf_conntrack_amanda.c
> @@ -37,7 +37,7 @@ MODULE_PARM_DESC(master_timeout, "timeout for the master connection");
> module_param(ts_algo, charp, 0400);
> MODULE_PARM_DESC(ts_algo, "textsearch algorithm to use (default kmp)");
>
> -unsigned int (*nf_nat_amanda_hook)(struct sk_buff *skb,
> +unsigned int (__rcu *nf_nat_amanda_hook)(struct sk_buff *skb,
> enum ip_conntrack_info ctinfo,
> unsigned int protoff,
> unsigned int matchoff,
> ?
Ack, I'll follow your suggestions and send a V2 shortly.
Thanks for the correction!
Regards,
Sun
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2] netfilter: amanda: fix RCU pointer typing for nf_nat_amanda_hook
2026-02-03 8:01 [PATCH] netfilter: amanda: fix RCU pointer typing for nf_nat_amanda_hook Sun Jian
2026-02-03 13:50 ` Florian Westphal
@ 2026-02-03 14:55 ` Sun Jian
2026-02-03 15:03 ` Florian Westphal
1 sibling, 1 reply; 11+ messages in thread
From: Sun Jian @ 2026-02-03 14:55 UTC (permalink / raw)
To: Florian Westphal
Cc: Pablo Neira Ayuso, Phil Sutter, Simon Horman, netfilter-devel,
netdev, linux-kernel, Sun Jian
Sparse reports "incompatible types in comparison expression" error in
nf_conntrack_amanda.c because nf_nat_amanda_hook is used with
rcu_dereference() but lacks the proper __rcu annotation.
Fix this by correctly placing the __rcu annotation inside the pointer
parentheses in both the declaration and definition. This allows the
standard rcu_dereference() to work correctly.
Suggested-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
---
v2:
- Correctly place __rcu annotation inside the parentheses as
suggested by Florian Westphal.
- Use standard rcu_dereference() instead of rcu_dereference_raw().
---
include/linux/netfilter/nf_conntrack_amanda.h | 12 +++++------
net/netfilter/nf_conntrack_amanda.c | 21 ++++++++++++-------
2 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/include/linux/netfilter/nf_conntrack_amanda.h b/include/linux/netfilter/nf_conntrack_amanda.h
index 6f0ac896fcc9..9f957598a9da 100644
--- a/include/linux/netfilter/nf_conntrack_amanda.h
+++ b/include/linux/netfilter/nf_conntrack_amanda.h
@@ -7,10 +7,10 @@
#include <linux/skbuff.h>
#include <net/netfilter/nf_conntrack_expect.h>
-extern unsigned int (*nf_nat_amanda_hook)(struct sk_buff *skb,
- enum ip_conntrack_info ctinfo,
- unsigned int protoff,
- unsigned int matchoff,
- unsigned int matchlen,
- struct nf_conntrack_expect *exp);
+extern unsigned int (__rcu *nf_nat_amanda_hook)(struct sk_buff *skb,
+ enum ip_conntrack_info ctinfo,
+ unsigned int protoff,
+ unsigned int matchoff,
+ unsigned int matchlen,
+ struct nf_conntrack_expect *exp);
#endif /* _NF_CONNTRACK_AMANDA_H */
diff --git a/net/netfilter/nf_conntrack_amanda.c b/net/netfilter/nf_conntrack_amanda.c
index 7be4c35e4795..2e3753758b9b 100644
--- a/net/netfilter/nf_conntrack_amanda.c
+++ b/net/netfilter/nf_conntrack_amanda.c
@@ -37,13 +37,13 @@ MODULE_PARM_DESC(master_timeout, "timeout for the master connection");
module_param(ts_algo, charp, 0400);
MODULE_PARM_DESC(ts_algo, "textsearch algorithm to use (default kmp)");
-unsigned int (*nf_nat_amanda_hook)(struct sk_buff *skb,
- enum ip_conntrack_info ctinfo,
- unsigned int protoff,
- unsigned int matchoff,
- unsigned int matchlen,
- struct nf_conntrack_expect *exp)
- __read_mostly;
+unsigned int (__rcu *nf_nat_amanda_hook)(struct sk_buff *skb,
+ enum ip_conntrack_info ctinfo,
+ unsigned int protoff,
+ unsigned int matchoff,
+ unsigned int matchlen,
+ struct nf_conntrack_expect *exp)
+ __read_mostly;
EXPORT_SYMBOL_GPL(nf_nat_amanda_hook);
enum amanda_strings {
@@ -98,7 +98,12 @@ static int amanda_help(struct sk_buff *skb,
u_int16_t len;
__be16 port;
int ret = NF_ACCEPT;
- typeof(nf_nat_amanda_hook) nf_nat_amanda;
+ unsigned int (*nf_nat_amanda)(struct sk_buff *skb,
+ enum ip_conntrack_info ctinfo,
+ unsigned int protoff,
+ unsigned int matchoff,
+ unsigned int matchlen,
+ struct nf_conntrack_expect *exp);
/* Only look at packets from the Amanda server */
if (CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL)
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH v2] netfilter: amanda: fix RCU pointer typing for nf_nat_amanda_hook
2026-02-03 14:55 ` [PATCH v2] " Sun Jian
@ 2026-02-03 15:03 ` Florian Westphal
2026-02-03 16:19 ` sun jian
0 siblings, 1 reply; 11+ messages in thread
From: Florian Westphal @ 2026-02-03 15:03 UTC (permalink / raw)
To: Sun Jian
Cc: Pablo Neira Ayuso, Phil Sutter, Simon Horman, netfilter-devel,
netdev, linux-kernel
Sun Jian <sun.jian.kdev@gmail.com> wrote:
> enum amanda_strings {
> @@ -98,7 +98,12 @@ static int amanda_help(struct sk_buff *skb,
> u_int16_t len;
> __be16 port;
> int ret = NF_ACCEPT;
> - typeof(nf_nat_amanda_hook) nf_nat_amanda;
> + unsigned int (*nf_nat_amanda)(struct sk_buff *skb,
> + enum ip_conntrack_info ctinfo,
> + unsigned int protoff,
> + unsigned int matchoff,
> + unsigned int matchlen,
> + struct nf_conntrack_expect *exp);
Why is that needed?
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH v2] netfilter: amanda: fix RCU pointer typing for nf_nat_amanda_hook
2026-02-03 15:03 ` Florian Westphal
@ 2026-02-03 16:19 ` sun jian
2026-02-03 16:59 ` Florian Westphal
0 siblings, 1 reply; 11+ messages in thread
From: sun jian @ 2026-02-03 16:19 UTC (permalink / raw)
To: Florian Westphal
Cc: Pablo Neira Ayuso, Phil Sutter, Simon Horman, netfilter-devel,
netdev, linux-kernel
On Tue, Feb 3, 2026 at 11:04 PM Florian Westphal <fw@strlen.de> wrote:
>
> Sun Jian <sun.jian.kdev@gmail.com> wrote:
> > enum amanda_strings {
> > @@ -98,7 +98,12 @@ static int amanda_help(struct sk_buff *skb,
> > u_int16_t len;
> > __be16 port;
> > int ret = NF_ACCEPT;
> > - typeof(nf_nat_amanda_hook) nf_nat_amanda;
> > + unsigned int (*nf_nat_amanda)(struct sk_buff *skb,
> > + enum ip_conntrack_info ctinfo,
> > + unsigned int protoff,
> > + unsigned int matchoff,
> > + unsigned int matchlen,
> > + struct nf_conntrack_expect *exp);
>
> Why is that needed?
Correct. Manual declaration is indeed verbose.
The reason I used it was that typeof(nf_nat_amanda_hook) carries over
the __rcu attribute to the local variable, which triggers a Sparse
warning when assigning the result of rcu_dereference().
I will switch to typeof(*nf_nat_amanda_hook) *nf_nat_amanda in V3.
Thanks for the guidance!
Regards,
Sun
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH v2] netfilter: amanda: fix RCU pointer typing for nf_nat_amanda_hook
2026-02-03 16:19 ` sun jian
@ 2026-02-03 16:59 ` Florian Westphal
2026-02-04 1:56 ` sun jian
0 siblings, 1 reply; 11+ messages in thread
From: Florian Westphal @ 2026-02-03 16:59 UTC (permalink / raw)
To: sun jian
Cc: Pablo Neira Ayuso, Phil Sutter, Simon Horman, netfilter-devel,
netdev, linux-kernel
sun jian <sun.jian.kdev@gmail.com> wrote:
> > Sun Jian <sun.jian.kdev@gmail.com> wrote:
> > > enum amanda_strings {
> > > @@ -98,7 +98,12 @@ static int amanda_help(struct sk_buff *skb,
> > > u_int16_t len;
> > > __be16 port;
> > > int ret = NF_ACCEPT;
> > > - typeof(nf_nat_amanda_hook) nf_nat_amanda;
> > > + unsigned int (*nf_nat_amanda)(struct sk_buff *skb,
> > > + enum ip_conntrack_info ctinfo,
> > > + unsigned int protoff,
> > > + unsigned int matchoff,
> > > + unsigned int matchlen,
> > > + struct nf_conntrack_expect *exp);
> >
> > Why is that needed?
> Correct. Manual declaration is indeed verbose.
>
> The reason I used it was that typeof(nf_nat_amanda_hook) carries over
> the __rcu attribute to the local variable, which triggers a Sparse
> warning when assigning the result of rcu_dereference().
sparse doesn't generate such a warning for me.
Also, this pattern you are changing here isn't specific to amanda, it
exists elsewhere as well:
net/netfilter/nf_conntrack_snmp.c:42:23: error: incompatible types in comparison expression (different address spaces):
net/netfilter/nf_conntrack_tftp.c:78:31: error: incompatible types in comparison expression (different address spaces):
net/netfilter/nf_conntrack_irc.c:242:38: error: incompatible types in comparison expression (different address spaces):
net/netfilter/nf_conntrack_ftp.c:521:22: error: incompatible types in comparison expression (different address spaces):
so why only fix this annotation for amanda?
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH v2] netfilter: amanda: fix RCU pointer typing for nf_nat_amanda_hook
2026-02-03 16:59 ` Florian Westphal
@ 2026-02-04 1:56 ` sun jian
2026-02-04 2:31 ` sun jian
0 siblings, 1 reply; 11+ messages in thread
From: sun jian @ 2026-02-04 1:56 UTC (permalink / raw)
To: Florian Westphal
Cc: Pablo Neira Ayuso, Phil Sutter, Simon Horman, netfilter-devel,
netdev, linux-kernel
On Wed, Feb 4, 2026 at 12:59 AM Florian Westphal <fw@strlen.de> wrote:
>
> sun jian <sun.jian.kdev@gmail.com> wrote:
> > > Sun Jian <sun.jian.kdev@gmail.com> wrote:
> > > > enum amanda_strings {
> > > > @@ -98,7 +98,12 @@ static int amanda_help(struct sk_buff *skb,
> > > > u_int16_t len;
> > > > __be16 port;
> > > > int ret = NF_ACCEPT;
> > > > - typeof(nf_nat_amanda_hook) nf_nat_amanda;
> > > > + unsigned int (*nf_nat_amanda)(struct sk_buff *skb,
> > > > + enum ip_conntrack_info ctinfo,
> > > > + unsigned int protoff,
> > > > + unsigned int matchoff,
> > > > + unsigned int matchlen,
> > > > + struct nf_conntrack_expect *exp);
> > >
> > > Why is that needed?
> > Correct. Manual declaration is indeed verbose.
> >
> > The reason I used it was that typeof(nf_nat_amanda_hook) carries over
> > the __rcu attribute to the local variable, which triggers a Sparse
> > warning when assigning the result of rcu_dereference().
>
> sparse doesn't generate such a warning for me.
I re-verified this with GCC 13.3.0 and Sparse v0.6.4-73-gfbdde312.
Even without LLVM=1, Sparse still reports the "different address spaces"
error for amanda on my machine:
net/netfilter/nf_conntrack_amanda.c:158:33: error: incompatible types
in comparison expression (different address spaces):
net/netfilter/nf_conntrack_amanda.c:158:33: unsigned int ( [noderef]
__rcu * )( ... ) net/netfilter/nf_conntrack_amanda.c:158:33: unsigned
int ( * )( ... )
It seems newer Sparse versions are more strict about RCU attributes on
function pointers.
To avoid manual declaration while stripping the __rcu attribute, I
will switch to:
typeof(*nf_nat_amanda_hook) *nf_nat_amanda;
>
> Also, this pattern you are changing here isn't specific to amanda, it
> exists elsewhere as well:
>
> net/netfilter/nf_conntrack_snmp.c:42:23: error: incompatible types in comparison expression (different address spaces):
> net/netfilter/nf_conntrack_tftp.c:78:31: error: incompatible types in comparison expression (different address spaces):
> net/netfilter/nf_conntrack_irc.c:242:38: error: incompatible types in comparison expression (different address spaces):
> net/netfilter/nf_conntrack_ftp.c:521:22: error: incompatible types in comparison expression (different address spaces):
>
> so why only fix this annotation for amanda?
Ack, I will prepare a V4 patch series to fix it for amanda, snmp,
tftp, irc, and ftp together.
Regards,
Sun
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH v2] netfilter: amanda: fix RCU pointer typing for nf_nat_amanda_hook
2026-02-04 1:56 ` sun jian
@ 2026-02-04 2:31 ` sun jian
2026-02-04 12:24 ` Florian Westphal
0 siblings, 1 reply; 11+ messages in thread
From: sun jian @ 2026-02-04 2:31 UTC (permalink / raw)
To: Florian Westphal
Cc: Pablo Neira Ayuso, Phil Sutter, Simon Horman, netfilter-devel,
netdev, linux-kernel
Hi Florian,
One quick clarification to my previous email regarding the change at line 101.
While line 101 itself doesn't trigger a Sparse warning, using
typeof(nf_nat_amanda_hook)
causes the local variable to inherit the __rcu attribute. This
"attribute inheritance"
is what leads to the "different address spaces" error during
assignment at line 158
when using rcu_dereference().
To keep the code concise while stripping the RCU attribute, I'll use
the typeof(*hook) * pattern
as discussed. I am currently preparing the v4 patch series which will
apply this refined fix to all
affected helpers (amanda, ftp, irc, snmp, and tftp) to clean up these
Sparse warnings across
the subsystem.
Sorry for the confusion in the earlier thread.
Regards,
Sun
On Wed, Feb 4, 2026 at 9:56 AM sun jian <sun.jian.kdev@gmail.com> wrote:
>
> On Wed, Feb 4, 2026 at 12:59 AM Florian Westphal <fw@strlen.de> wrote:
> >
> > sun jian <sun.jian.kdev@gmail.com> wrote:
> > > > Sun Jian <sun.jian.kdev@gmail.com> wrote:
> > > > > enum amanda_strings {
> > > > > @@ -98,7 +98,12 @@ static int amanda_help(struct sk_buff *skb,
> > > > > u_int16_t len;
> > > > > __be16 port;
> > > > > int ret = NF_ACCEPT;
> > > > > - typeof(nf_nat_amanda_hook) nf_nat_amanda;
> > > > > + unsigned int (*nf_nat_amanda)(struct sk_buff *skb,
> > > > > + enum ip_conntrack_info ctinfo,
> > > > > + unsigned int protoff,
> > > > > + unsigned int matchoff,
> > > > > + unsigned int matchlen,
> > > > > + struct nf_conntrack_expect *exp);
> > > >
> > > > Why is that needed?
> > > Correct. Manual declaration is indeed verbose.
> > >
> > > The reason I used it was that typeof(nf_nat_amanda_hook) carries over
> > > the __rcu attribute to the local variable, which triggers a Sparse
> > > warning when assigning the result of rcu_dereference().
> >
> > sparse doesn't generate such a warning for me.
>
> I re-verified this with GCC 13.3.0 and Sparse v0.6.4-73-gfbdde312.
> Even without LLVM=1, Sparse still reports the "different address spaces"
> error for amanda on my machine:
>
> net/netfilter/nf_conntrack_amanda.c:158:33: error: incompatible types
> in comparison expression (different address spaces):
> net/netfilter/nf_conntrack_amanda.c:158:33: unsigned int ( [noderef]
> __rcu * )( ... ) net/netfilter/nf_conntrack_amanda.c:158:33: unsigned
> int ( * )( ... )
>
> It seems newer Sparse versions are more strict about RCU attributes on
> function pointers.
> To avoid manual declaration while stripping the __rcu attribute, I
> will switch to:
> typeof(*nf_nat_amanda_hook) *nf_nat_amanda;
>
> >
> > Also, this pattern you are changing here isn't specific to amanda, it
> > exists elsewhere as well:
> >
> > net/netfilter/nf_conntrack_snmp.c:42:23: error: incompatible types in comparison expression (different address spaces):
> > net/netfilter/nf_conntrack_tftp.c:78:31: error: incompatible types in comparison expression (different address spaces):
> > net/netfilter/nf_conntrack_irc.c:242:38: error: incompatible types in comparison expression (different address spaces):
> > net/netfilter/nf_conntrack_ftp.c:521:22: error: incompatible types in comparison expression (different address spaces):
> >
> > so why only fix this annotation for amanda?
> Ack, I will prepare a V4 patch series to fix it for amanda, snmp,
> tftp, irc, and ftp together.
>
> Regards,
>
> Sun
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH v2] netfilter: amanda: fix RCU pointer typing for nf_nat_amanda_hook
2026-02-04 2:31 ` sun jian
@ 2026-02-04 12:24 ` Florian Westphal
2026-02-04 14:49 ` sun jian
0 siblings, 1 reply; 11+ messages in thread
From: Florian Westphal @ 2026-02-04 12:24 UTC (permalink / raw)
To: sun jian
Cc: Pablo Neira Ayuso, Phil Sutter, Simon Horman, netfilter-devel,
netdev, linux-kernel
sun jian <sun.jian.kdev@gmail.com> wrote:
> To keep the code concise while stripping the RCU attribute, I'll use
> the typeof(*hook) * pattern
No, please leave this alone, the code is fine as-is, all sparse warnings
are due to missing annotations only.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2] netfilter: amanda: fix RCU pointer typing for nf_nat_amanda_hook
2026-02-04 12:24 ` Florian Westphal
@ 2026-02-04 14:49 ` sun jian
0 siblings, 0 replies; 11+ messages in thread
From: sun jian @ 2026-02-04 14:49 UTC (permalink / raw)
To: Florian Westphal
Cc: Pablo Neira Ayuso, Phil Sutter, Simon Horman, netfilter-devel,
netdev, linux-kernel
On Wed, Feb 4, 2026 at 8:24 PM Florian Westphal <fw@strlen.de> wrote:
>
> sun jian <sun.jian.kdev@gmail.com> wrote:
> > To keep the code concise while stripping the RCU attribute, I'll use
> > the typeof(*hook) * pattern
>
> No, please leave this alone, the code is fine as-is, all sparse warnings
> are due to missing annotations only.
Ack. You are right: I've double-checked my environment and confirmed
that adding the __rcu is sufficient to resolve those warnings.
I will just annotate them and leave other code as-is. V4 is on the way.
Regards,
sun jian
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-02-04 14:49 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-03 8:01 [PATCH] netfilter: amanda: fix RCU pointer typing for nf_nat_amanda_hook Sun Jian
2026-02-03 13:50 ` Florian Westphal
2026-02-03 14:36 ` sun jian
2026-02-03 14:55 ` [PATCH v2] " Sun Jian
2026-02-03 15:03 ` Florian Westphal
2026-02-03 16:19 ` sun jian
2026-02-03 16:59 ` Florian Westphal
2026-02-04 1:56 ` sun jian
2026-02-04 2:31 ` sun jian
2026-02-04 12:24 ` Florian Westphal
2026-02-04 14:49 ` sun jian
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox