aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorIdo Yariv <ido@wizery.com>2011-12-01 06:55:08 -0500
committerThomas Gleixner <tglx@linutronix.de>2011-12-02 05:54:24 -0500
commit550acb19269d65f32e9ac4ddb26c2b2070e37f1c (patch)
tree804925b363142e47a4a26f1afcfb8f9e302bed0e /kernel
parentb930c26416c4ea6855726fd977145ccea9afbdda (diff)
genirq: Fix race condition when stopping the irq thread
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. [ tglx: Simplified it a bit ] Signed-off-by: Ido Yariv <ido@wizery.com> Link: http://lkml.kernel.org/r/1322740508-22640-1-git-send-email-ido@wizery.com Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: stable@kernel.org
Diffstat (limited to 'kernel')
-rw-r--r--kernel/irq/manage.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 0e2b179bc7b3..1da999f5e746 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -623,8 +623,9 @@ static irqreturn_t irq_nested_primary_handler(int irq, void *dev_id)
623 623
624static int irq_wait_for_interrupt(struct irqaction *action) 624static int irq_wait_for_interrupt(struct irqaction *action)
625{ 625{
626 set_current_state(TASK_INTERRUPTIBLE);
627
626 while (!kthread_should_stop()) { 628 while (!kthread_should_stop()) {
627 set_current_state(TASK_INTERRUPTIBLE);
628 629
629 if (test_and_clear_bit(IRQTF_RUNTHREAD, 630 if (test_and_clear_bit(IRQTF_RUNTHREAD,
630 &action->thread_flags)) { 631 &action->thread_flags)) {
@@ -632,7 +633,9 @@ static int irq_wait_for_interrupt(struct irqaction *action)
632 return 0; 633 return 0;
633 } 634 }
634 schedule(); 635 schedule();
636 set_current_state(TASK_INTERRUPTIBLE);
635 } 637 }
638 __set_current_state(TASK_RUNNING);
636 return -1; 639 return -1;
637} 640}
638 641