diff options
author | Peter Hurley <peter@hurleysoftware.com> | 2011-08-05 10:41:35 -0400 |
---|---|---|
committer | Gustavo F. Padovan <padovan@profusion.mobi> | 2011-08-11 18:50:27 -0400 |
commit | 751c10a56802513a6b057c8cf1552cecc1c9afde (patch) | |
tree | 958b4624a551577f68e0f0e357112637a10c520a /net | |
parent | 7bdb8a5cf17f66614a9897645efcd4ccc27535ee (diff) |
Bluetooth: bnep: Fix deadlock in session deletion
Commit f4d7cd4a4c introduced the usage of kthread API.
kthread_stop is a blocking function which returns only when
the thread exits. In this case, the thread can't exit because it's
waiting for the write lock, which is being held by bnep_del_connection()
which is waiting for the thread to exit -- deadlock.
Use atomic_t/wake_up_process instead to signal to the thread to exit.
Signed-off-by: Jaikumar Ganesh <jaikumar@google.com>
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
Diffstat (limited to 'net')
-rw-r--r-- | net/bluetooth/bnep/bnep.h | 1 | ||||
-rw-r--r-- | net/bluetooth/bnep/core.c | 9 |
2 files changed, 6 insertions, 4 deletions
diff --git a/net/bluetooth/bnep/bnep.h b/net/bluetooth/bnep/bnep.h index 8e6c06158f8e..e7ee5314f39a 100644 --- a/net/bluetooth/bnep/bnep.h +++ b/net/bluetooth/bnep/bnep.h | |||
@@ -155,6 +155,7 @@ struct bnep_session { | |||
155 | unsigned int role; | 155 | unsigned int role; |
156 | unsigned long state; | 156 | unsigned long state; |
157 | unsigned long flags; | 157 | unsigned long flags; |
158 | atomic_t terminate; | ||
158 | struct task_struct *task; | 159 | struct task_struct *task; |
159 | 160 | ||
160 | struct ethhdr eh; | 161 | struct ethhdr eh; |
diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c index 7e8ff3c24942..d9edfe8bf9d6 100644 --- a/net/bluetooth/bnep/core.c +++ b/net/bluetooth/bnep/core.c | |||
@@ -487,7 +487,7 @@ static int bnep_session(void *arg) | |||
487 | while (1) { | 487 | while (1) { |
488 | set_current_state(TASK_INTERRUPTIBLE); | 488 | set_current_state(TASK_INTERRUPTIBLE); |
489 | 489 | ||
490 | if (kthread_should_stop()) | 490 | if (atomic_read(&s->terminate)) |
491 | break; | 491 | break; |
492 | /* RX */ | 492 | /* RX */ |
493 | while ((skb = skb_dequeue(&sk->sk_receive_queue))) { | 493 | while ((skb = skb_dequeue(&sk->sk_receive_queue))) { |
@@ -642,9 +642,10 @@ int bnep_del_connection(struct bnep_conndel_req *req) | |||
642 | down_read(&bnep_session_sem); | 642 | down_read(&bnep_session_sem); |
643 | 643 | ||
644 | s = __bnep_get_session(req->dst); | 644 | s = __bnep_get_session(req->dst); |
645 | if (s) | 645 | if (s) { |
646 | kthread_stop(s->task); | 646 | atomic_inc(&s->terminate); |
647 | else | 647 | wake_up_process(s->task); |
648 | } else | ||
648 | err = -ENOENT; | 649 | err = -ENOENT; |
649 | 650 | ||
650 | up_read(&bnep_session_sem); | 651 | up_read(&bnep_session_sem); |