* [PATCH] Bluetooth: btmrvl: fix thread stopping race
@ 2013-06-11 19:40 Daniel Drake
2013-06-13 10:32 ` Gustavo Padovan
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Drake @ 2013-06-11 19:40 UTC (permalink / raw)
To: marcel, bzhao, gustavo, johan.hedberg; +Cc: linux-bluetooth
There is currently a race condition in the btmrvl_remove_card() which
is causing hangs on suspend for OLPC. When the race occurs,
kthread_stop() never returns.
The problem is that btmrvl_service_main_thread() calls kthread_should_stop()
and then does a fair number of things before restarting the loop and
sleeping.
If the thread gets stopped after kthread_should_stop() is checked, but
before the sleep happens, the thread will go to sleep and won't necessarily
be woken up.
Move the kthread_should_stop() check into a race-free place.
Signed-off-by: Daniel Drake <dsd@laptop.org>
---
drivers/bluetooth/btmrvl_main.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/bluetooth/btmrvl_main.c b/drivers/bluetooth/btmrvl_main.c
index 3a4343b..9a9f518 100644
--- a/drivers/bluetooth/btmrvl_main.c
+++ b/drivers/bluetooth/btmrvl_main.c
@@ -498,6 +498,10 @@ static int btmrvl_service_main_thread(void *data)
add_wait_queue(&thread->wait_q, &wait);
set_current_state(TASK_INTERRUPTIBLE);
+ if (kthread_should_stop()) {
+ BT_DBG("main_thread: break from main thread");
+ break;
+ }
if (adapter->wakeup_tries ||
((!adapter->int_count) &&
@@ -513,11 +517,6 @@ static int btmrvl_service_main_thread(void *data)
BT_DBG("main_thread woke up");
- if (kthread_should_stop()) {
- BT_DBG("main_thread: break from main thread");
- break;
- }
-
spin_lock_irqsave(&priv->driver_lock, flags);
if (adapter->int_count) {
adapter->int_count = 0;
--
1.8.1.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Bluetooth: btmrvl: fix thread stopping race
2013-06-11 19:40 [PATCH] Bluetooth: btmrvl: fix thread stopping race Daniel Drake
@ 2013-06-13 10:32 ` Gustavo Padovan
0 siblings, 0 replies; 2+ messages in thread
From: Gustavo Padovan @ 2013-06-13 10:32 UTC (permalink / raw)
To: Daniel Drake; +Cc: marcel, bzhao, johan.hedberg, linux-bluetooth
Hi Daniel,
* Daniel Drake <dsd@laptop.org> [2013-06-11 15:40:20 -0400]:
> There is currently a race condition in the btmrvl_remove_card() which
> is causing hangs on suspend for OLPC. When the race occurs,
> kthread_stop() never returns.
>
> The problem is that btmrvl_service_main_thread() calls kthread_should_stop()
> and then does a fair number of things before restarting the loop and
> sleeping.
>
> If the thread gets stopped after kthread_should_stop() is checked, but
> before the sleep happens, the thread will go to sleep and won't necessarily
> be woken up.
>
> Move the kthread_should_stop() check into a race-free place.
>
> Signed-off-by: Daniel Drake <dsd@laptop.org>
> ---
> drivers/bluetooth/btmrvl_main.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
Patch has been applied to bluetooth.git. Thanks.
Gustavo
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-06-13 10:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-11 19:40 [PATCH] Bluetooth: btmrvl: fix thread stopping race Daniel Drake
2013-06-13 10:32 ` Gustavo Padovan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).