phonet: add __rcu annotations
Subsystems (3)
PATCH 1/1 phonet: add __rcu annotations
Removes following sparse errors.
make C=2 net/phonet/socket.o net/phonet/af_phonet.o
CHECK net/phonet/socket.cnet/phonet/socket.c:619:14: error: incompatible types in comparison expression (different address spaces):net/phonet/socket.c:619:14: struct sock [noderef] __rcu *net/phonet/socket.c:619:14: struct sock *net/phonet/socket.c:642:17: error: incompatible types in comparison expression (different address spaces):net/phonet/socket.c:642:17: struct sock [noderef] __rcu *net/phonet/socket.c:642:17: struct sock *net/phonet/socket.c:658:17: error: incompatible types in comparison expression (different address spaces):net/phonet/socket.c:658:17: struct sock [noderef] __rcu *net/phonet/socket.c:658:17: struct sock *net/phonet/socket.c:677:25: error: incompatible types in comparison expression (different address spaces):net/phonet/socket.c:677:25: struct sock [noderef] __rcu *net/phonet/socket.c:677:25: struct sock *net/phonet/socket.c:726:21: warning: context imbalance in 'pn_res_seq_start' - wrong count at exit net/phonet/socket.c:741:13: warning: context imbalance in 'pn_res_seq_stop' - wrong count at exit
CHECK net/phonet/af_phonet.cnet/phonet/af_phonet.c:35:14: error: incompatible types in comparison expression (different address spaces):net/phonet/af_phonet.c:35:14: struct phonet_protocol const [noderef] __rcu *net/phonet/af_phonet.c:35:14: struct phonet_protocol const *net/phonet/af_phonet.c:474:17: error: incompatible types in comparison expression (different address spaces):net/phonet/af_phonet.c:474:17: struct phonet_protocol const [noderef] __rcu *net/phonet/af_phonet.c:474:17: struct phonet_protocol const *net/phonet/af_phonet.c:486:9: error: incompatible types in comparison expression (different address spaces):net/phonet/af_phonet.c:486:9: struct phonet_protocol const [noderef] __rcu *net/phonet/af_phonet.c:486:9: struct phonet_protocol const *
--- net/phonet/af_phonet.c | 4 ++-- net/phonet/socket.c | 23 ++++++++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-)
net/phonet/af_phonet.c +2 -2
@@ -22,7 +22,7 @@#include <net/phonet/pn_dev.h> /* Transport protocol registration */ -static const struct phonet_protocol *proto_tab[PHONET_NPROTO ]__read_mostly ; +static const struct phonet_protocol __rcu *proto_tab[PHONET_NPROTO ]__read_mostly ;static const struct phonet_protocol *phonet_proto_get (unsigned int protocol) {
@@ -482,7 +482,7 @@ void phonet_proto_unregister(unsigned int protocol, const struct phonet_protocol *pp) {mutex_lock (&proto_tab_lock); -BUG_ON (proto_tab[protocol] != pp); +BUG_ON (rcu_access_pointer (proto_tab[protocol]) != pp);RCU_INIT_POINTER (proto_tab[protocol],NULL );mutex_unlock (&proto_tab_lock);synchronize_rcu ();
net/phonet/socket.c +12 -11
@@ -602,7 +602,7 @@ const struct seq_operations pn_sock_seq_ops = {#endif static struct { -struct sock *sk[256 ]; +struct sock __rcu *sk[256 ]; } pnres;/*
@@ -654,7 +654,7 @@ int pn_sock_unbind_res(struct sock *sk, u8 res)return -EPERM ;mutex_lock (&resource_mutex); -if (pnres.sk[res] == sk) { +if (rcu_access_pointer (pnres.sk[res]) == sk) {RCU_INIT_POINTER (pnres.sk[res],NULL ); ret =0 ; }
@@ -673,7 +673,7 @@ void pn_sock_unbind_all_res(struct sock *sk)mutex_lock (&resource_mutex);for (res =0 ; res <256 ; res++) { -if (pnres.sk[res] == sk) { +if (rcu_access_pointer (pnres.sk[res]) == sk) {RCU_INIT_POINTER (pnres.sk[res],NULL ); match++; }
@@ -688,7 +688,7 @@ void pn_sock_unbind_all_res(struct sock *sk) }#ifdef CONFIG_PROC_FS -static struct sock **pn_res_get_idx (struct seq_file *seq,loff_t pos) +static struct sock __rcu **pn_res_get_idx (struct seq_file *seq,loff_t pos) {struct net *net =seq_file_net (seq);unsigned int i;
@@ -697,7 +697,7 @@ static struct sock **pn_res_get_idx(struct seq_file *seq, loff_t pos)return NULL ;for (i =0 ; i <256 ; i++) { -if (pnres.sk[i] ==NULL ) +if (rcu_access_pointer (pnres.sk[i]) ==NULL )continue ;if (!pos)return pnres.sk + i;
@@ -706,7 +706,7 @@ static struct sock **pn_res_get_idx(struct seq_file *seq, loff_t pos)return NULL ; } -static struct sock **pn_res_get_next (struct seq_file *seq,struct sock **sk) +static struct sock __rcu **pn_res_get_next (struct seq_file *seq,struct sock __rcu **sk) {struct net *net =seq_file_net (seq);unsigned int i;
@@ -728,7 +728,7 @@ static void *pn_res_seq_start(struct seq_file *seq, loff_t *pos)static void *pn_res_seq_next (struct seq_file *seq,void *v,loff_t *pos) { -struct sock **sk; +struct sock __rcu **sk;if (v ==SEQ_START_TOKEN ) sk =pn_res_get_idx (seq,0 );
@@ -747,11 +747,12 @@ static void pn_res_seq_stop(struct seq_file *seq, void *v)static int pn_res_seq_show (struct seq_file *seq,void *v) {seq_setwidth (seq,63 ); -if (v ==SEQ_START_TOKEN ) +if (v ==SEQ_START_TOKEN ) {seq_puts (seq,"rs uid inode" ); -else { -struct sock **psk = v; -struct sock *sk = *psk; + }else { +struct sock __rcu **psk = v; +struct sock *sk =rcu_dereference_protected (*psk, +lockdep_is_held (&resource_mutex)); seq_printf(seq, "%02X %5u %lu", (int) (psk - pnres.sk),
Signature · 1 line
2.50.1.703.g449372360f-goog
Le 11 août 2025 23:52:52 GMT+09:00, Eric Dumazet <[email protected]> a écrit :
Quoted 29 lines
Removes following sparse errors.
make C=2
net/phonet/socket.onet/phonet/af_phonet.o
CHECKnet/phonet/socket.cnet/phonet/socket.c:619:14: error: incompatible types in comparison expression (different address spaces):net/phonet/socket.c:619:14: struct sock [noderef]__rcu*net/phonet/socket.c:619:14: struct sock *net/phonet/socket.c:642:17: error: incompatible types in comparison expression (different address spaces):net/phonet/socket.c:642:17: struct sock [noderef]__rcu*net/phonet/socket.c:642:17: struct sock *net/phonet/socket.c:658:17: error: incompatible types in comparison expression (different address spaces):net/phonet/socket.c:658:17: struct sock [noderef]__rcu*net/phonet/socket.c:658:17: struct sock *net/phonet/socket.c:677:25: error: incompatible types in comparison expression (different address spaces):net/phonet/socket.c:677:25: struct sock [noderef]__rcu*net/phonet/socket.c:677:25: struct sock *net/phonet/socket.c:726:21: warning: context imbalance in 'pn_res_seq_start' - wrong count at exitnet/phonet/socket.c:741:13: warning: context imbalance in 'pn_res_seq_stop' - wrong count at exit
CHECKnet/phonet/af_phonet.cnet/phonet/af_phonet.c:35:14: error: incompatible types in comparison expression (different address spaces):net/phonet/af_phonet.c:35:14: structphonet_protocolconst [noderef]__rcu*net/phonet/af_phonet.c:35:14: structphonet_protocolconst *net/phonet/af_phonet.c:474:17: error: incompatible types in comparison expression (different address spaces):net/phonet/af_phonet.c:474:17: structphonet_protocolconst [noderef]__rcu*net/phonet/af_phonet.c:474:17: structphonet_protocolconst *net/phonet/af_phonet.c:486:9: error: incompatible types in comparison expression (different address spaces):net/phonet/af_phonet.c:486:9: structphonet_protocolconst [noderef]__rcu*net/phonet/af_phonet.c:486:9: structphonet_protocolconst *
Quoted 2 lines
Signed-off-by Eric Dumazet <[email protected]>Cc Remi Denis-Courmont <[email protected]>
(We should probably replace that BUG_ON with a WARN_ON but that's a separate issue.)
Quoted 111 lines
---
net/phonet/af_phonet.c| 4 ++--net/phonet/socket.c| 23 ++++++++++++-----------2 files changed, 14 insertions(+), 13 deletions(-)net/phonet/af_phonet.c +2
-2@@ -22,7 +22,7 @@#include <net/phonet/pn_dev.h> /* Transport protocol registration */ -static const struct phonet_protocol *proto_tab[PHONET_NPROTO ]__read_mostly ; +static const struct phonet_protocol __rcu *proto_tab[PHONET_NPROTO ]__read_mostly ;static const struct phonet_protocol *phonet_proto_get (unsigned int protocol) {@@ -482,7 +482,7 @@ void phonet_proto_unregister(unsigned int protocol, const struct phonet_protocol *pp) {mutex_lock (&proto_tab_lock); -BUG_ON (proto_tab[protocol] != pp); +BUG_ON (rcu_access_pointer (proto_tab[protocol]) != pp);RCU_INIT_POINTER (proto_tab[protocol],NULL );mutex_unlock (&proto_tab_lock);synchronize_rcu ();net/phonet/socket.c +12
-11@@ -602,7 +602,7 @@ const struct seq_operations pn_sock_seq_ops = {#endif static struct { -struct sock *sk[256 ]; +struct sock __rcu *sk[256 ]; } pnres;/* @@ -654,7 +654,7 @@ int pn_sock_unbind_res(struct sock *sk, u8 res)return -EPERM ;mutex_lock (&resource_mutex); -if (pnres.sk[res] == sk) { +if (rcu_access_pointer (pnres.sk[res]) == sk) {RCU_INIT_POINTER (pnres.sk[res],NULL ); ret =0 ; }@@ -673,7 +673,7 @@ void pn_sock_unbind_all_res(struct sock *sk)mutex_lock (&resource_mutex);for (res =0 ; res <256 ; res++) { -if (pnres.sk[res] == sk) { +if (rcu_access_pointer (pnres.sk[res]) == sk) {RCU_INIT_POINTER (pnres.sk[res],NULL ); match++; }@@ -688,7 +688,7 @@ void pn_sock_unbind_all_res(struct sock *sk) }#ifdef CONFIG_PROC_FS -static struct sock **pn_res_get_idx (struct seq_file *seq,loff_t pos) +static struct sock __rcu **pn_res_get_idx (struct seq_file *seq,loff_t pos) {struct net *net =seq_file_net (seq);unsigned int i;@@ -697,7 +697,7 @@ static struct sock **pn_res_get_idx(struct seq_file *seq, loff_t pos)return NULL ;for (i =0 ; i <256 ; i++) { -if (pnres.sk[i] ==NULL ) +if (rcu_access_pointer (pnres.sk[i]) ==NULL )continue ;if (!pos)return pnres.sk + i;@@ -706,7 +706,7 @@ static struct sock **pn_res_get_idx(struct seq_file *seq, loff_t pos)return NULL ; } -static struct sock **pn_res_get_next (struct seq_file *seq,struct sock **sk) +static struct sock __rcu **pn_res_get_next (struct seq_file *seq,struct sock __rcu **sk) {struct net *net =seq_file_net (seq);unsigned int i;@@ -728,7 +728,7 @@ static void *pn_res_seq_start(struct seq_file *seq, loff_t *pos)static void *pn_res_seq_next (struct seq_file *seq,void *v,loff_t *pos) { -struct sock **sk; +struct sock __rcu **sk;if (v ==SEQ_START_TOKEN ) sk =pn_res_get_idx (seq,0 );@@ -747,11 +747,12 @@ static void pn_res_seq_stop(struct seq_file *seq, void *v)static int pn_res_seq_show (struct seq_file *seq,void *v) {seq_setwidth (seq,63 ); -if (v ==SEQ_START_TOKEN ) +if (v ==SEQ_START_TOKEN ) {seq_puts (seq,"rs uid inode" ); -else { -struct sock **psk = v; -struct sock *sk = *psk; + }else { +struct sock __rcu **psk = v; +struct sock *sk =rcu_dereference_protected (*psk, +lockdep_is_held (&resource_mutex)); seq_printf(seq, "%02X %5u %lu", (int) (psk - pnres.sk),
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 29 lines · On Mon, 11 Aug 2025 14:52:52 +0000 you wrote:
Removes following sparse errors.
make C=2
net/phonet/socket.onet/phonet/af_phonet.o
CHECKnet/phonet/socket.cnet/phonet/socket.c:619:14: error: incompatible types in comparison expression (different address spaces):net/phonet/socket.c:619:14: struct sock [noderef]__rcu*net/phonet/socket.c:619:14: struct sock *net/phonet/socket.c:642:17: error: incompatible types in comparison expression (different address spaces):net/phonet/socket.c:642:17: struct sock [noderef]__rcu*net/phonet/socket.c:642:17: struct sock *net/phonet/socket.c:658:17: error: incompatible types in comparison expression (different address spaces):net/phonet/socket.c:658:17: struct sock [noderef]__rcu*net/phonet/socket.c:658:17: struct sock *net/phonet/socket.c:677:25: error: incompatible types in comparison expression (different address spaces):net/phonet/socket.c:677:25: struct sock [noderef]__rcu*net/phonet/socket.c:677:25: struct sock *net/phonet/socket.c:726:21: warning: context imbalance in 'pn_res_seq_start' - wrong count at exitnet/phonet/socket.c:741:13: warning: context imbalance in 'pn_res_seq_stop' - wrong count at exit
CHECKnet/phonet/af_phonet.cnet/phonet/af_phonet.c:35:14: error: incompatible types in comparison expression (different address spaces):net/phonet/af_phonet.c:35:14: structphonet_protocolconst [noderef]__rcu*net/phonet/af_phonet.c:35:14: structphonet_protocolconst *net/phonet/af_phonet.c:474:17: error: incompatible types in comparison expression (different address spaces):net/phonet/af_phonet.c:474:17: structphonet_protocolconst [noderef]__rcu*net/phonet/af_phonet.c:474:17: structphonet_protocolconst *net/phonet/af_phonet.c:486:9: error: incompatible types in comparison expression (different address spaces):net/phonet/af_phonet.c:486:9: structphonet_protocolconst [noderef]__rcu*net/phonet/af_phonet.c:486:9: structphonet_protocolconst *
Quoted 1 line
[...]
Here is the summary with links:
- [net-next] phonet: add __rcu annotations
https://git.kernel.org/netdev/net-next/c/86e3d52bd3e9
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html