Skip to content

Commit 190683a

Browse files
Eric Dumazetdavem330
authored andcommitted
net: net_families __rcu annotations
Use modern RCU API / annotations for net_families array. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e85eb11 commit 190683a

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎net/socket.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static const struct file_operations socket_file_ops = {
156156
*/
157157

158158
static DEFINE_SPINLOCK(net_family_lock);
159-
static const struct net_proto_family *net_families[NPROTO] __read_mostly;
159+
static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
160160

161161
/*
162162
* Statistics counters of the socket lists
@@ -1200,7 +1200,7 @@ int __sock_create(struct net *net, int family, int type, int protocol,
12001200
* requested real, full-featured networking support upon configuration.
12011201
* Otherwise module support will break!
12021202
*/
1203-
if (net_families[family] == NULL)
1203+
if (rcu_access_pointer(net_families[family]) == NULL)
12041204
request_module("net-pf-%d", family);
12051205
#endif
12061206

@@ -2332,10 +2332,11 @@ int sock_register(const struct net_proto_family *ops)
23322332
}
23332333

23342334
spin_lock(&net_family_lock);
2335-
if (net_families[ops->family])
2335+
if (rcu_dereference_protected(net_families[ops->family],
2336+
lockdep_is_held(&net_family_lock)))
23362337
err = -EEXIST;
23372338
else {
2338-
net_families[ops->family] = ops;
2339+
rcu_assign_pointer(net_families[ops->family], ops);
23392340
err = 0;
23402341
}
23412342
spin_unlock(&net_family_lock);
@@ -2363,7 +2364,7 @@ void sock_unregister(int family)
23632364
BUG_ON(family < 0 || family >= NPROTO);
23642365

23652366
spin_lock(&net_family_lock);
2366-
net_families[family] = NULL;
2367+
rcu_assign_pointer(net_families[family], NULL);
23672368
spin_unlock(&net_family_lock);
23682369

23692370
synchronize_rcu();

0 commit comments

Comments
 (0)