lkml.org 
[lkml]   [2011]   [Dec]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] irq: Fix race condition when stopping the irq thread
Date
In irq_wait_for_interrupt(), the should_stop member is verified before
setting the task's state to TASK_INTERRUPTIBLE and calling schedule().
In case kthread_stop sets should_stop and wakes up the process after
should_stop is checked by the irq thread but before the task's state is
changed, the irq thread might never exit:

kthread_stop irq_wait_for_interrupt
------------ ----------------------

...
... while (!kthread_should_stop()) {
kthread->should_stop = 1;
wake_up_process(k);
wait_for_completion(&kthread->exited);
...
set_current_state(TASK_INTERRUPTIBLE);

...

schedule();
}
...

Fix this by checking if the thread should stop after modifying the
task's state.

Signed-off-by: Ido Yariv <ido@wizery.com>
Cc: stable@kernel.org
---
kernel/irq/manage.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 0e2b179..3194d5e 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -631,7 +631,11 @@ static int irq_wait_for_interrupt(struct irqaction *action)
__set_current_state(TASK_RUNNING);
return 0;
}
- schedule();
+
+ if (!kthread_should_stop())
+ schedule();
+ else
+ __set_current_state(TASK_RUNNING);
}
return -1;
}
--
1.7.7.3


\
 
 \ /
  Last update: 2011-12-01 12:57    [W:0.043 / U:0.884 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site