Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

phonet: add __rcu annotations

Removes following sparse errors.

make C=2 net/phonet/socket.o net/phonet/af_phonet.o
CHECK net/phonet/socket.c
net/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.c
net/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 *

Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Rémi Denis-Courmont <courmisch@gmail.com>
Link: https://patch.msgid.link/20250811145252.1007242-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Dumazet and committed by
Jakub Kicinski
86e3d52b f8262b8d

+14 -13
+2 -2
net/phonet/af_phonet.c
··· 22 22 #include <net/phonet/pn_dev.h> 23 23 24 24 /* Transport protocol registration */ 25 - static const struct phonet_protocol *proto_tab[PHONET_NPROTO] __read_mostly; 25 + static const struct phonet_protocol __rcu *proto_tab[PHONET_NPROTO] __read_mostly; 26 26 27 27 static const struct phonet_protocol *phonet_proto_get(unsigned int protocol) 28 28 { ··· 482 482 const struct phonet_protocol *pp) 483 483 { 484 484 mutex_lock(&proto_tab_lock); 485 - BUG_ON(proto_tab[protocol] != pp); 485 + BUG_ON(rcu_access_pointer(proto_tab[protocol]) != pp); 486 486 RCU_INIT_POINTER(proto_tab[protocol], NULL); 487 487 mutex_unlock(&proto_tab_lock); 488 488 synchronize_rcu();
+12 -11
net/phonet/socket.c
··· 602 602 #endif 603 603 604 604 static struct { 605 - struct sock *sk[256]; 605 + struct sock __rcu *sk[256]; 606 606 } pnres; 607 607 608 608 /* ··· 654 654 return -EPERM; 655 655 656 656 mutex_lock(&resource_mutex); 657 - if (pnres.sk[res] == sk) { 657 + if (rcu_access_pointer(pnres.sk[res]) == sk) { 658 658 RCU_INIT_POINTER(pnres.sk[res], NULL); 659 659 ret = 0; 660 660 } ··· 673 673 674 674 mutex_lock(&resource_mutex); 675 675 for (res = 0; res < 256; res++) { 676 - if (pnres.sk[res] == sk) { 676 + if (rcu_access_pointer(pnres.sk[res]) == sk) { 677 677 RCU_INIT_POINTER(pnres.sk[res], NULL); 678 678 match++; 679 679 } ··· 688 688 } 689 689 690 690 #ifdef CONFIG_PROC_FS 691 - static struct sock **pn_res_get_idx(struct seq_file *seq, loff_t pos) 691 + static struct sock __rcu **pn_res_get_idx(struct seq_file *seq, loff_t pos) 692 692 { 693 693 struct net *net = seq_file_net(seq); 694 694 unsigned int i; ··· 697 697 return NULL; 698 698 699 699 for (i = 0; i < 256; i++) { 700 - if (pnres.sk[i] == NULL) 700 + if (rcu_access_pointer(pnres.sk[i]) == NULL) 701 701 continue; 702 702 if (!pos) 703 703 return pnres.sk + i; ··· 706 706 return NULL; 707 707 } 708 708 709 - static struct sock **pn_res_get_next(struct seq_file *seq, struct sock **sk) 709 + static struct sock __rcu **pn_res_get_next(struct seq_file *seq, struct sock __rcu **sk) 710 710 { 711 711 struct net *net = seq_file_net(seq); 712 712 unsigned int i; ··· 728 728 729 729 static void *pn_res_seq_next(struct seq_file *seq, void *v, loff_t *pos) 730 730 { 731 - struct sock **sk; 731 + struct sock __rcu **sk; 732 732 733 733 if (v == SEQ_START_TOKEN) 734 734 sk = pn_res_get_idx(seq, 0); ··· 747 747 static int pn_res_seq_show(struct seq_file *seq, void *v) 748 748 { 749 749 seq_setwidth(seq, 63); 750 - if (v == SEQ_START_TOKEN) 750 + if (v == SEQ_START_TOKEN) { 751 751 seq_puts(seq, "rs uid inode"); 752 - else { 753 - struct sock **psk = v; 754 - struct sock *sk = *psk; 752 + } else { 753 + struct sock __rcu **psk = v; 754 + struct sock *sk = rcu_dereference_protected(*psk, 755 + lockdep_is_held(&resource_mutex)); 755 756 756 757 seq_printf(seq, "%02X %5u %lu", 757 758 (int) (psk - pnres.sk),