Skip to content

Commit e0ad61e

Browse files
Eric Dumazetdavem330
authored andcommitted
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>
1 parent 1c31720 commit e0ad61e

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

‎include/net/protocol.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ struct inet_protosw {
8989
#define INET_PROTOSW_PERMANENT 0x02 /* Permanent protocols are unremovable. */
9090
#define INET_PROTOSW_ICSK 0x04 /* Is this an inet_connection_sock? */
9191

92-
extern const struct net_protocol *inet_protos[MAX_INET_PROTOS];
92+
extern const struct net_protocol __rcu *inet_protos[MAX_INET_PROTOS];
9393

9494
#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];
9696
#endif
9797

9898
extern int inet_add_protocol(const struct net_protocol *prot, unsigned char num);

‎net/ipv4/protocol.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <linux/spinlock.h>
2929
#include <net/protocol.h>
3030

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;
3232

3333
/*
3434
* Add a protocol handler to the hash tables
@@ -38,7 +38,8 @@ int inet_add_protocol(const struct net_protocol *prot, unsigned char protocol)
3838
{
3939
int hash = protocol & (MAX_INET_PROTOS - 1);
4040

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;
4243
}
4344
EXPORT_SYMBOL(inet_add_protocol);
4445

@@ -50,7 +51,8 @@ int inet_del_protocol(const struct net_protocol *prot, unsigned char protocol)
5051
{
5152
int ret, hash = protocol & (MAX_INET_PROTOS - 1);
5253

53-
ret = (cmpxchg(&inet_protos[hash], prot, NULL) == prot) ? 0 : -1;
54+
ret = (cmpxchg((const struct net_protocol **)&inet_protos[hash],
55+
prot, NULL) == prot) ? 0 : -1;
5456

5557
synchronize_net();
5658

‎net/ipv6/protocol.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525
#include <linux/spinlock.h>
2626
#include <net/protocol.h>
2727

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;
2929

3030
int inet6_add_protocol(const struct inet6_protocol *prot, unsigned char protocol)
3131
{
3232
int hash = protocol & (MAX_INET_PROTOS - 1);
3333

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;
3536
}
3637
EXPORT_SYMBOL(inet6_add_protocol);
3738

@@ -43,7 +44,8 @@ int inet6_del_protocol(const struct inet6_protocol *prot, unsigned char protocol
4344
{
4445
int ret, hash = protocol & (MAX_INET_PROTOS - 1);
4546

46-
ret = (cmpxchg(&inet6_protos[hash], prot, NULL) == prot) ? 0 : -1;
47+
ret = (cmpxchg((const struct inet6_protocol **)&inet6_protos[hash],
48+
prot, NULL) == prot) ? 0 : -1;
4749

4850
synchronize_net();
4951

0 commit comments

Comments
 (0)