Merge branch 'devel' of master.kernel.org:/home/rmk/linux-2.6-arm
[safe/jmp/linux-2.6] / drivers / macintosh / smu.c
index 77ad192..888448c 100644 (file)
@@ -19,6 +19,7 @@
  *    the userland interface
  */
 
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/device.h>
@@ -35,6 +36,9 @@
 #include <linux/sysdev.h>
 #include <linux/poll.h>
 #include <linux/mutex.h>
+#include <linux/of_device.h>
+#include <linux/of_platform.h>
+#include <linux/slab.h>
 
 #include <asm/byteorder.h>
 #include <asm/io.h>
@@ -45,8 +49,6 @@
 #include <asm/sections.h>
 #include <asm/abs_addr.h>
 #include <asm/uaccess.h>
-#include <asm/of_device.h>
-#include <asm/of_platform.h>
 
 #define VERSION "0.7"
 #define AUTHOR  "(c) 2005 Benjamin Herrenschmidt, IBM Corp."
@@ -474,6 +476,7 @@ int __init smu_init (void)
 {
        struct device_node *np;
        const u32 *data;
+       int ret = 0;
 
         np = of_find_node_by_type(NULL, "smu");
         if (np == NULL)
@@ -483,13 +486,11 @@ int __init smu_init (void)
 
        if (smu_cmdbuf_abs == 0) {
                printk(KERN_ERR "SMU: Command buffer not allocated !\n");
-               return -EINVAL;
+               ret = -EINVAL;
+               goto fail_np;
        }
 
        smu = alloc_bootmem(sizeof(struct smu_device));
-       if (smu == NULL)
-               return -ENOMEM;
-       memset(smu, 0, sizeof(*smu));
 
        spin_lock_init(&smu->lock);
        INIT_LIST_HEAD(&smu->cmd_list);
@@ -507,14 +508,14 @@ int __init smu_init (void)
        smu->db_node = of_find_node_by_name(NULL, "smu-doorbell");
        if (smu->db_node == NULL) {
                printk(KERN_ERR "SMU: Can't find doorbell GPIO !\n");
-               goto fail;
+               ret = -ENXIO;
+               goto fail_bootmem;
        }
        data = of_get_property(smu->db_node, "reg", NULL);
        if (data == NULL) {
-               of_node_put(smu->db_node);
-               smu->db_node = NULL;
                printk(KERN_ERR "SMU: Can't find doorbell GPIO address !\n");
-               goto fail;
+               ret = -ENXIO;
+               goto fail_db_node;
        }
 
        /* Current setup has one doorbell GPIO that does both doorbell
@@ -548,7 +549,8 @@ int __init smu_init (void)
        smu->db_buf = ioremap(0x8000860c, 0x1000);
        if (smu->db_buf == NULL) {
                printk(KERN_ERR "SMU: Can't map doorbell buffer pointer !\n");
-               goto fail;
+               ret = -ENXIO;
+               goto fail_msg_node;
        }
 
        /* U3 has an issue with NAP mode when issuing SMU commands */
@@ -559,10 +561,17 @@ int __init smu_init (void)
        sys_ctrler = SYS_CTRLER_SMU;
        return 0;
 
- fail:
+fail_msg_node:
+       if (smu->msg_node)
+               of_node_put(smu->msg_node);
+fail_db_node:
+       of_node_put(smu->db_node);
+fail_bootmem:
+       free_bootmem((unsigned long)smu, sizeof(struct smu_device));
        smu = NULL;
-       return -ENXIO;
-
+fail_np:
+       of_node_put(np);
+       return ret;
 }
 
 
@@ -652,7 +661,7 @@ static int smu_platform_probe(struct of_device* dev,
        return 0;
 }
 
-static struct of_device_id smu_platform_match[] =
+static const struct of_device_id smu_platform_match[] =
 {
        {
                .type           = "smu",
@@ -1083,10 +1092,12 @@ static int smu_open(struct inode *inode, struct file *file)
        pp->mode = smu_file_commands;
        init_waitqueue_head(&pp->wait);
 
+       lock_kernel();
        spin_lock_irqsave(&smu_clist_lock, flags);
        list_add(&pp->list, &smu_clist);
        spin_unlock_irqrestore(&smu_clist_lock, flags);
        file->private_data = pp;
+       unlock_kernel();
 
        return 0;
 }