Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 171543
b: refs/heads/master
c: 7ed0132
h: refs/heads/master
i:
  171541: 247b0e5
  171539: 412f64b
  171535: 3392547
v: v3
  • Loading branch information
Rémi Denis-Courmont authored and David S. Miller committed Nov 14, 2009
1 parent 7090564 commit 0292edb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 998221c26b86a7edd621e66b437628c5ec0f8e9b
refs/heads/master: 7ed0132f232b11ae58b6d868e8d7ada9dfa066d7
20 changes: 11 additions & 9 deletions trunk/net/phonet/af_phonet.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

/* Transport protocol registration */
static struct phonet_protocol *proto_tab[PHONET_NPROTO] __read_mostly;
static DEFINE_SPINLOCK(proto_tab_lock);

static struct phonet_protocol *phonet_proto_get(int protocol)
{
Expand All @@ -44,11 +43,11 @@ static struct phonet_protocol *phonet_proto_get(int protocol)
if (protocol >= PHONET_NPROTO)
return NULL;

spin_lock(&proto_tab_lock);
rcu_read_lock();
pp = proto_tab[protocol];
if (pp && !try_module_get(pp->prot->owner))
pp = NULL;
spin_unlock(&proto_tab_lock);
rcu_read_unlock();

return pp;
}
Expand Down Expand Up @@ -439,6 +438,8 @@ static struct packet_type phonet_packet_type __read_mostly = {
.func = phonet_rcv,
};

static DEFINE_MUTEX(proto_tab_lock);

int __init_or_module phonet_proto_register(int protocol,
struct phonet_protocol *pp)
{
Expand All @@ -451,23 +452,24 @@ int __init_or_module phonet_proto_register(int protocol,
if (err)
return err;

spin_lock(&proto_tab_lock);
mutex_lock(&proto_tab_lock);
if (proto_tab[protocol])
err = -EBUSY;
else
proto_tab[protocol] = pp;
spin_unlock(&proto_tab_lock);
rcu_assign_pointer(proto_tab[protocol], pp);
mutex_unlock(&proto_tab_lock);

return err;
}
EXPORT_SYMBOL(phonet_proto_register);

void phonet_proto_unregister(int protocol, struct phonet_protocol *pp)
{
spin_lock(&proto_tab_lock);
mutex_lock(&proto_tab_lock);
BUG_ON(proto_tab[protocol] != pp);
proto_tab[protocol] = NULL;
spin_unlock(&proto_tab_lock);
rcu_assign_pointer(proto_tab[protocol], NULL);
mutex_unlock(&proto_tab_lock);
synchronize_rcu();
proto_unregister(pp->prot);
}
EXPORT_SYMBOL(phonet_proto_unregister);
Expand Down

0 comments on commit 0292edb

Please sign in to comment.