Skip to content

Commit

Permalink
net: add __rcu annotations to protocol
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Eric Dumazet authored and davem330 committed Oct 27, 2010
1 parent 1c31720 commit e0ad61e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions include/net/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ struct inet_protosw {
#define INET_PROTOSW_PERMANENT 0x02 /* Permanent protocols are unremovable. */
#define INET_PROTOSW_ICSK 0x04 /* Is this an inet_connection_sock? */

extern const struct net_protocol *inet_protos[MAX_INET_PROTOS];
extern const struct net_protocol __rcu *inet_protos[MAX_INET_PROTOS];

#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
extern const struct inet6_protocol *inet6_protos[MAX_INET_PROTOS];
extern const struct inet6_protocol __rcu *inet6_protos[MAX_INET_PROTOS];
#endif

extern int inet_add_protocol(const struct net_protocol *prot, unsigned char num);
Expand Down
8 changes: 5 additions & 3 deletions net/ipv4/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <linux/spinlock.h>
#include <net/protocol.h>

const struct net_protocol *inet_protos[MAX_INET_PROTOS] __read_mostly;
const struct net_protocol __rcu *inet_protos[MAX_INET_PROTOS] __read_mostly;

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

return !cmpxchg(&inet_protos[hash], NULL, prot) ? 0 : -1;
return !cmpxchg((const struct net_protocol **)&inet_protos[hash],
NULL, prot) ? 0 : -1;
}
EXPORT_SYMBOL(inet_add_protocol);

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

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

synchronize_net();

Expand Down
8 changes: 5 additions & 3 deletions net/ipv6/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
#include <linux/spinlock.h>
#include <net/protocol.h>

const struct inet6_protocol *inet6_protos[MAX_INET_PROTOS] __read_mostly;
const struct inet6_protocol __rcu *inet6_protos[MAX_INET_PROTOS] __read_mostly;

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

return !cmpxchg(&inet6_protos[hash], NULL, prot) ? 0 : -1;
return !cmpxchg((const struct inet6_protocol **)&inet6_protos[hash],
NULL, prot) ? 0 : -1;
}
EXPORT_SYMBOL(inet6_add_protocol);

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

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

synchronize_net();

Expand Down

0 comments on commit e0ad61e

Please sign in to comment.