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.
Change-Id: I538cd17c102cb31b3212c794086a9c2baedb4b14
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>
[skrovvid@codeaurora.org: kthread_should_stop api call is avoided]
Signed-off-by: Srinivas Krovvidi <skrovvid@codeaurora.org>
This commit is contained in:
committed by
Srinivas Krovvidi
parent
e8992f2213
commit
2db3637b45
@@ -155,6 +155,7 @@ struct bnep_session {
|
|||||||
unsigned int role;
|
unsigned int role;
|
||||||
unsigned long state;
|
unsigned long state;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
atomic_t terminate;
|
||||||
struct task_struct *task;
|
struct task_struct *task;
|
||||||
|
|
||||||
struct ethhdr eh;
|
struct ethhdr eh;
|
||||||
|
|||||||
@@ -484,9 +484,11 @@ static int bnep_session(void *arg)
|
|||||||
|
|
||||||
init_waitqueue_entry(&wait, current);
|
init_waitqueue_entry(&wait, current);
|
||||||
add_wait_queue(sk_sleep(sk), &wait);
|
add_wait_queue(sk_sleep(sk), &wait);
|
||||||
while (!kthread_should_stop()) {
|
while (1) {
|
||||||
set_current_state(TASK_INTERRUPTIBLE);
|
set_current_state(TASK_INTERRUPTIBLE);
|
||||||
|
|
||||||
|
if (atomic_read(&s->terminate))
|
||||||
|
break;
|
||||||
/* RX */
|
/* RX */
|
||||||
while ((skb = skb_dequeue(&sk->sk_receive_queue))) {
|
while ((skb = skb_dequeue(&sk->sk_receive_queue))) {
|
||||||
skb_orphan(skb);
|
skb_orphan(skb);
|
||||||
@@ -643,9 +645,10 @@ int bnep_del_connection(struct bnep_conndel_req *req)
|
|||||||
down_read(&bnep_session_sem);
|
down_read(&bnep_session_sem);
|
||||||
|
|
||||||
s = __bnep_get_session(req->dst);
|
s = __bnep_get_session(req->dst);
|
||||||
if (s)
|
if (s) {
|
||||||
kthread_stop(s->task);
|
atomic_inc(&s->terminate);
|
||||||
else
|
wake_up_process(s->task);
|
||||||
|
} else
|
||||||
err = -ENOENT;
|
err = -ENOENT;
|
||||||
|
|
||||||
up_read(&bnep_session_sem);
|
up_read(&bnep_session_sem);
|
||||||
|
|||||||
Reference in New Issue
Block a user