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

net: add __rcu annotations to protocol

Add __rcu annotations to :
struct net_protocol *inet_protos
struct net_protocol *inet6_protos

And use appropriate casts to reduce sparse warnings if
CONFIG_SPARSE_RCU_POINTER=y

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Eric Dumazet and committed by
David S. Miller
e0ad61ec 1c31720a

+12 -8
+2 -2
include/net/protocol.h
··· 89 89 #define INET_PROTOSW_PERMANENT 0x02 /* Permanent protocols are unremovable. */ 90 90 #define INET_PROTOSW_ICSK 0x04 /* Is this an inet_connection_sock? */ 91 91 92 - extern const struct net_protocol *inet_protos[MAX_INET_PROTOS]; 92 + extern const struct net_protocol __rcu *inet_protos[MAX_INET_PROTOS]; 93 93 94 94 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE) 95 - extern const struct inet6_protocol *inet6_protos[MAX_INET_PROTOS]; 95 + extern const struct inet6_protocol __rcu *inet6_protos[MAX_INET_PROTOS]; 96 96 #endif 97 97 98 98 extern int inet_add_protocol(const struct net_protocol *prot, unsigned char num);
+5 -3
net/ipv4/protocol.c
··· 28 28 #include <linux/spinlock.h> 29 29 #include <net/protocol.h> 30 30 31 - const struct net_protocol *inet_protos[MAX_INET_PROTOS] __read_mostly; 31 + const struct net_protocol __rcu *inet_protos[MAX_INET_PROTOS] __read_mostly; 32 32 33 33 /* 34 34 * Add a protocol handler to the hash tables ··· 38 38 { 39 39 int hash = protocol & (MAX_INET_PROTOS - 1); 40 40 41 - return !cmpxchg(&inet_protos[hash], NULL, prot) ? 0 : -1; 41 + return !cmpxchg((const struct net_protocol **)&inet_protos[hash], 42 + NULL, prot) ? 0 : -1; 42 43 } 43 44 EXPORT_SYMBOL(inet_add_protocol); 44 45 ··· 51 50 { 52 51 int ret, hash = protocol & (MAX_INET_PROTOS - 1); 53 52 54 - ret = (cmpxchg(&inet_protos[hash], prot, NULL) == prot) ? 0 : -1; 53 + ret = (cmpxchg((const struct net_protocol **)&inet_protos[hash], 54 + prot, NULL) == prot) ? 0 : -1; 55 55 56 56 synchronize_net(); 57 57
+5 -3
net/ipv6/protocol.c
··· 25 25 #include <linux/spinlock.h> 26 26 #include <net/protocol.h> 27 27 28 - const struct inet6_protocol *inet6_protos[MAX_INET_PROTOS] __read_mostly; 28 + const struct inet6_protocol __rcu *inet6_protos[MAX_INET_PROTOS] __read_mostly; 29 29 30 30 int inet6_add_protocol(const struct inet6_protocol *prot, unsigned char protocol) 31 31 { 32 32 int hash = protocol & (MAX_INET_PROTOS - 1); 33 33 34 - return !cmpxchg(&inet6_protos[hash], NULL, prot) ? 0 : -1; 34 + return !cmpxchg((const struct inet6_protocol **)&inet6_protos[hash], 35 + NULL, prot) ? 0 : -1; 35 36 } 36 37 EXPORT_SYMBOL(inet6_add_protocol); 37 38 ··· 44 43 { 45 44 int ret, hash = protocol & (MAX_INET_PROTOS - 1); 46 45 47 - ret = (cmpxchg(&inet6_protos[hash], prot, NULL) == prot) ? 0 : -1; 46 + ret = (cmpxchg((const struct inet6_protocol **)&inet6_protos[hash], 47 + prot, NULL) == prot) ? 0 : -1; 48 48 49 49 synchronize_net(); 50 50