nfsd4: put_nfs4_client does not require state lock
[safe/jmp/linux-2.6] / drivers / macintosh / therm_windtunnel.c
index a1d3a98..3da0a02 100644 (file)
 #include <linux/i2c.h>
 #include <linux/slab.h>
 #include <linux/init.h>
+#include <linux/kthread.h>
+#include <linux/of_platform.h>
 
 #include <asm/prom.h>
 #include <asm/machdep.h>
 #include <asm/io.h>
 #include <asm/system.h>
 #include <asm/sections.h>
-#include <asm/of_platform.h>
 #include <asm/macio.h>
 
 #define LOG_TEMP               0                       /* continously log temperature */
 
-#define I2C_DRIVERID_G4FAN     0x9001                  /* fixme */
-
 static int                     do_probe( struct i2c_adapter *adapter, int addr, int kind);
 
 /* scan 0x48-0x4f (DS1775) and 0x2c-2x2f (ADM1030) */
-static unsigned short          normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
+static const unsigned short    normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
                                                 0x4c, 0x4d, 0x4e, 0x4f,
                                                 0x2c, 0x2d, 0x2e, 0x2f,
                                                 I2C_CLIENT_END };
@@ -61,10 +60,9 @@ I2C_CLIENT_INSMOD;
 
 static struct {
        volatile int            running;
-       struct completion       completion;
-       pid_t                   poll_task;
+       struct task_struct      *poll_task;
        
-       struct semaphore        lock;
+       struct mutex            lock;
        struct of_device        *of_dev;
        
        struct i2c_client       *thermostat;
@@ -223,6 +221,7 @@ static void
 setup_hardware( void )
 {
        int val;
+       int err;
 
        /* save registers (if we unload the module) */
        x.r0 = read_reg( x.fan, 0x00, 1 );
@@ -265,8 +264,11 @@ setup_hardware( void )
        x.upind = -1;
        /* tune_fan( fan_up_table[x.upind].fan_setting ); */
 
-       device_create_file( &x.of_dev->dev, &dev_attr_cpu_temperature );
-       device_create_file( &x.of_dev->dev, &dev_attr_case_temperature );
+       err = device_create_file( &x.of_dev->dev, &dev_attr_cpu_temperature );
+       err |= device_create_file( &x.of_dev->dev, &dev_attr_case_temperature );
+       if (err)
+               printk(KERN_WARNING
+                       "Failed to create temperature attribute file(s).\n");
 }
 
 static void
@@ -282,27 +284,27 @@ restore_regs( void )
        write_reg( x.fan, 0x00, x.r0, 1 );
 }
 
-static int
-control_loop( void *dummy )
+static int control_loop(void *dummy)
 {
-       daemonize("g4fand");
-
-       down( &x.lock );
+       mutex_lock(&x.lock);
        setup_hardware();
+       mutex_unlock(&x.lock);
 
-       while( x.running ) {
-               up( &x.lock );
-
+       for (;;) {
                msleep_interruptible(8000);
-               
-               down( &x.lock );
+               if (kthread_should_stop())
+                       break;
+
+               mutex_lock(&x.lock);
                poll_temp();
+               mutex_unlock(&x.lock);
        }
 
+       mutex_lock(&x.lock);
        restore_regs();
-       up( &x.lock );
+       mutex_unlock(&x.lock);
 
-       complete_and_exit( &x.completion, 0 );
+       return 0;
 }
 
 
@@ -322,8 +324,7 @@ do_attach( struct i2c_adapter *adapter )
                ret = i2c_probe( adapter, &addr_data, &do_probe );
                if( x.thermostat && x.fan ) {
                        x.running = 1;
-                       init_completion( &x.completion );
-                       x.poll_task = kernel_thread( control_loop, NULL, SIGCHLD | CLONE_KERNEL );
+                       x.poll_task = kthread_run(control_loop, NULL, "g4fand");
                }
        }
        return ret;
@@ -339,7 +340,8 @@ do_detach( struct i2c_client *client )
        else {
                if( x.running ) {
                        x.running = 0;
-                       wait_for_completion( &x.completion );
+                       kthread_stop(x.poll_task);
+                       x.poll_task = NULL;
                }
                if( client == x.thermostat )
                        x.thermostat = NULL;
@@ -357,7 +359,6 @@ static struct i2c_driver g4fan_driver = {
        .driver = {
                .name   = "therm_windtunnel",
        },
-       .id             = I2C_DRIVERID_G4FAN,
        .attach_adapter = do_attach,
        .detach_client  = do_detach,
 };
@@ -431,9 +432,8 @@ do_probe( struct i2c_adapter *adapter, int addr, int kind )
                                     | I2C_FUNC_SMBUS_WRITE_BYTE) )
                return 0;
 
-       if( !(cl=kmalloc(sizeof(*cl), GFP_KERNEL)) )
+       if( !(cl=kzalloc(sizeof(*cl), GFP_KERNEL)) )
                return -ENOMEM;
-       memset( cl, 0, sizeof(struct i2c_client) );
 
        cl->addr = addr;
        cl->adapter = adapter;
@@ -459,7 +459,8 @@ therm_of_probe( struct of_device *dev, const struct of_device_id *match )
 static int
 therm_of_remove( struct of_device *dev )
 {
-       return i2c_del_driver( &g4fan_driver );
+       i2c_del_driver( &g4fan_driver );
+       return 0;
 }
 
 static struct of_device_id therm_of_match[] = {{
@@ -488,11 +489,11 @@ g4fan_init( void )
        const struct apple_thermal_info *info;
        struct device_node *np;
 
-       init_MUTEX( &x.lock );
+       mutex_init(&x.lock);
 
        if( !(np=of_find_node_by_name(NULL, "power-mgt")) )
                return -ENODEV;
-       info = get_property(np, "thermal-info", NULL);
+       info = of_get_property(np, "thermal-info", NULL);
        of_node_put(np);
 
        if( !info || !machine_is_compatible("PowerMac3,6") )