@@ -60,7 +60,6 @@ static atomic_t extracting;
int cpci_debug;
static struct cpci_hp_controller *controller;
static struct task_struct *cpci_thread;
-static int thread_finished;
static int enable_slot(struct hotplug_slot *slot);
static int disable_slot(struct hotplug_slot *slot);
@@ -341,7 +340,8 @@ cpci_hp_intr(int irq, void *data)
controller->ops->disable_irq();
/* Trigger processing by the event thread */
- wake_up_process(cpci_thread);
+ if (cpci_thread)
+ wake_up_process(cpci_thread);
return IRQ_HANDLED;
}
@@ -508,7 +508,6 @@ event_thread(void *data)
msleep(500);
} else if (rc < 0) {
dbg("%s - error checking slots", __func__);
- thread_finished = 1;
goto out;
}
} while (atomic_read(&extracting) && !kthread_should_stop());
@@ -540,7 +539,6 @@ poll_thread(void *data)
msleep(500);
} else if (rc < 0) {
dbg("%s - error checking slots", __func__);
- thread_finished = 1;
goto out;
}
} while (atomic_read(&extracting) && !kthread_should_stop());
@@ -562,15 +560,24 @@ cpci_start_thread(void)
err("Can't start up our thread");
return PTR_ERR(cpci_thread);
}
- thread_finished = 0;
+ get_task_struct(cpci_thread);
+
return 0;
}
static void
cpci_stop_thread(void)
{
- kthread_stop(cpci_thread);
- thread_finished = 1;
+ struct task_struct *tp;
+
+ if (cpci_thread) {
+ local_irq_disable();
+ tp = cpci_thread;
+ cpci_thread = NULL;
+ local_irq_enable();
+ kthread_stop(tp);
+ put_task_struct(tp);
+ }
}
int
@@ -627,8 +634,7 @@ cpci_hp_unregister_controller(struct cpci_hp_controller *old_controller)
int status = 0;
if (controller) {
- if (!thread_finished)
- cpci_stop_thread();
+ cpci_stop_thread();
if (controller->irq)
free_irq(controller->irq, controller->dev_id);
controller = NULL;
@@ -680,12 +686,13 @@ cpci_hp_stop(void)
{
if (!controller)
return -ENODEV;
+ cpci_stop_thread();
if (controller->irq) {
/* Stop enum interrupt processing */
dbg("%s - disabling irq", __func__);
controller->ops->disable_irq();
+ synchronize_irq(controller->irq);
}
- cpci_stop_thread();
return 0;
}