From: Colin Leroy <colin@colino.net>

Use kthread_stop() and kthread_should_stop() instead of monitor_running and
wait_completion().

Signed-off-by: Colin Leroy <colin@colino.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/drivers/macintosh/therm_adt746x.c |   25 ++++++++++++-------------
 1 files changed, 12 insertions(+), 13 deletions(-)

diff -puN drivers/macintosh/therm_adt746x.c~use-kthread_stop-in-therm_adt746x drivers/macintosh/therm_adt746x.c
--- 25/drivers/macintosh/therm_adt746x.c~use-kthread_stop-in-therm_adt746x	2004-09-30 23:56:50.036553976 -0700
+++ 25-akpm/drivers/macintosh/therm_adt746x.c	2004-09-30 23:56:50.041553216 -0700
@@ -71,8 +71,7 @@ static enum {ADT7460, ADT7467} therm_typ
 static int therm_bus, therm_address;
 static struct of_device * of_dev;
 static struct thermostat* thermostat;
-static int monitor_running;
-static struct completion monitor_task_compl;
+static struct task_struct *thread_therm = NULL;
 
 static int attach_one_thermostat(struct i2c_adapter *adapter, int addr, int busno);
 static void write_both_fan_speed(struct thermostat *th, int speed);
@@ -136,9 +135,8 @@ detach_thermostat(struct i2c_adapter *ad
 
 	th = thermostat;
 
-	if (monitor_running) {
-		monitor_running = 0;
-		wait_for_completion(&monitor_task_compl);
+	if (thread_therm != NULL) {
+		kthread_stop(thread_therm);
 	}
 		
 	printk(KERN_INFO "adt746x: Putting max temperatures back from %d, %d, %d,"
@@ -237,9 +235,7 @@ static int monitor_task(void *arg)
 #ifdef DEBUG
 	int mfan_speed;
 #endif
-	monitor_running = 1;
-
-	while(monitor_running)
+	while(!kthread_should_stop())
 	{
 		msleep_interruptible(2000);
 
@@ -316,7 +312,6 @@ static int monitor_task(void *arg)
 #endif		
 	}
 
-	complete_and_exit(&monitor_task_compl, 0);
 	return 0;
 }
 
@@ -382,7 +377,7 @@ attach_one_thermostat(struct i2c_adapter
 	thermostat = th;
 
 	if (i2c_attach_client(&th->clt)) {
-		printk("adt746x: Thermostat failed to attach client !\n");
+		printk(KERN_INFO "adt746x: Thermostat failed to attach client !\n");
 		thermostat = NULL;
 		kfree(th);
 		return -ENODEV;
@@ -398,9 +393,13 @@ attach_one_thermostat(struct i2c_adapter
 		write_both_fan_speed(th, -1);
 	}
 	
-	init_completion(&monitor_task_compl);
-	
-	kthread_run(monitor_task, th, "kfand");
+	thread_therm = kthread_run(monitor_task, th, "kfand");
+
+	if (thread_therm == ERR_PTR(-ENOMEM)) {
+		printk(KERN_INFO "adt746x: Kthread creation failed\n");
+		thread_therm = NULL;
+		return -ENOMEM;
+	}
 
 	return 0;
 }
_