Commit 66f2e3e1 authored by Ralf Bächle's avatar Ralf Bächle

Protect linkfail_list with a spinlock instead of the previous cli / sti mess.

parent 3a62a477
...@@ -10,6 +10,7 @@ af_ax25.c:ax25_connect: ...@@ -10,6 +10,7 @@ af_ax25.c:ax25_connect:
} }
Do the spinlocks ax25_list_lock, ax25_uid_lock, ax25_route_lock, Do the spinlocks ax25_list_lock, ax25_uid_lock, ax25_route_lock,
protocol_list_lock and ax25_dev_lock really have to be interrupt safe? protocol_list_lock, ax25_dev_lock and linkfail_lockreally have to be interrupt
safe?
What locking will be needed for linkfail_list and listen_list? What locking will be needed for listen_list?
...@@ -47,6 +47,7 @@ static struct linkfail_struct { ...@@ -47,6 +47,7 @@ static struct linkfail_struct {
struct linkfail_struct *next; struct linkfail_struct *next;
void (*func)(ax25_cb *, int); void (*func)(ax25_cb *, int);
} *linkfail_list; } *linkfail_list;
static spinlock_t linkfail_lock = SPIN_LOCK_UNLOCKED;
static struct listen_struct { static struct listen_struct {
struct listen_struct *next; struct listen_struct *next;
...@@ -122,31 +123,27 @@ int ax25_linkfail_register(void (*func)(ax25_cb *, int)) ...@@ -122,31 +123,27 @@ int ax25_linkfail_register(void (*func)(ax25_cb *, int))
linkfail->func = func; linkfail->func = func;
save_flags(flags); spin_lock_irqsave(&linkfail_lock, flags);
cli();
linkfail->next = linkfail_list; linkfail->next = linkfail_list;
linkfail_list = linkfail; linkfail_list = linkfail;
spin_unlock_irqrestore(&linkfail_lock, flags);
restore_flags(flags);
return 1; return 1;
} }
void ax25_linkfail_release(void (*func)(ax25_cb *, int)) void ax25_linkfail_release(void (*func)(ax25_cb *, int))
{ {
struct linkfail_struct *s, *linkfail = linkfail_list; struct linkfail_struct *s, *linkfail;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&linkfail_lock, flags);
linkfail = linkfail_list;
if (linkfail == NULL) if (linkfail == NULL)
return; return;
save_flags(flags);
cli();
if (linkfail->func == func) { if (linkfail->func == func) {
linkfail_list = linkfail->next; linkfail_list = linkfail->next;
restore_flags(flags); spin_unlock_irqrestore(&linkfail_lock, flags);
kfree(linkfail); kfree(linkfail);
return; return;
} }
...@@ -155,15 +152,14 @@ void ax25_linkfail_release(void (*func)(ax25_cb *, int)) ...@@ -155,15 +152,14 @@ void ax25_linkfail_release(void (*func)(ax25_cb *, int))
if (linkfail->next->func == func) { if (linkfail->next->func == func) {
s = linkfail->next; s = linkfail->next;
linkfail->next = linkfail->next->next; linkfail->next = linkfail->next->next;
restore_flags(flags); spin_unlock_irqrestore(&linkfail_lock, flags);
kfree(s); kfree(s);
return; return;
} }
linkfail = linkfail->next; linkfail = linkfail->next;
} }
spin_unlock_irqrestore(&linkfail_lock, flags);
restore_flags(flags);
} }
int ax25_listen_register(ax25_address *callsign, struct net_device *dev) int ax25_listen_register(ax25_address *callsign, struct net_device *dev)
...@@ -255,9 +251,12 @@ int ax25_listen_mine(ax25_address *callsign, struct net_device *dev) ...@@ -255,9 +251,12 @@ int ax25_listen_mine(ax25_address *callsign, struct net_device *dev)
void ax25_link_failed(ax25_cb *ax25, int reason) void ax25_link_failed(ax25_cb *ax25, int reason)
{ {
struct linkfail_struct *linkfail; struct linkfail_struct *linkfail;
unsigned long flags;
spin_lock_irqsave(&linkfail_lock, flags);
for (linkfail = linkfail_list; linkfail != NULL; linkfail = linkfail->next) for (linkfail = linkfail_list; linkfail != NULL; linkfail = linkfail->next)
(linkfail->func)(ax25, reason); (linkfail->func)(ax25, reason);
spin_unlock_irqrestore(&linkfail_lock, flags);
} }
int ax25_protocol_is_registered(unsigned int pid) int ax25_protocol_is_registered(unsigned int pid)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment