Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/pci-2.6
[sfrench/cifs-2.6.git] / drivers / firmware / dcdbas.c
index 3a4e5c5b4e1fc9d0fb421f9ed3cedd38a5f1fa26..1865b56fb141643878b50b4874c4be56f612ff0c 100644 (file)
@@ -8,7 +8,7 @@
  *
  *  See Documentation/dcdbas.txt for more information.
  *
- *  Copyright (C) 1995-2005 Dell Inc.
+ *  Copyright (C) 1995-2006 Dell Inc.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License v2.0 as published by
 #include <linux/spinlock.h>
 #include <linux/string.h>
 #include <linux/types.h>
+#include <linux/mutex.h>
 #include <asm/io.h>
 #include <asm/semaphore.h>
 
 #include "dcdbas.h"
 
 #define DRIVER_NAME            "dcdbas"
-#define DRIVER_VERSION         "5.6.0-2"
+#define DRIVER_VERSION         "5.6.0-3.2"
 #define DRIVER_DESCRIPTION     "Dell Systems Management Base Driver"
 
 static struct platform_device *dcdbas_pdev;
@@ -48,7 +49,7 @@ static u8 *smi_data_buf;
 static dma_addr_t smi_data_buf_handle;
 static unsigned long smi_data_buf_size;
 static u32 smi_data_buf_phys_addr;
-static DECLARE_MUTEX(smi_data_lock);
+static DEFINE_MUTEX(smi_data_lock);
 
 static unsigned int host_control_action;
 static unsigned int host_control_smi_type;
@@ -139,9 +140,9 @@ static ssize_t smi_data_buf_size_store(struct device *dev,
        buf_size = simple_strtoul(buf, NULL, 10);
 
        /* make sure SMI data buffer is at least buf_size */
-       down(&smi_data_lock);
+       mutex_lock(&smi_data_lock);
        ret = smi_data_buf_realloc(buf_size);
-       up(&smi_data_lock);
+       mutex_unlock(&smi_data_lock);
        if (ret)
                return ret;
 
@@ -154,7 +155,7 @@ static ssize_t smi_data_read(struct kobject *kobj, char *buf, loff_t pos,
        size_t max_read;
        ssize_t ret;
 
-       down(&smi_data_lock);
+       mutex_lock(&smi_data_lock);
 
        if (pos >= smi_data_buf_size) {
                ret = 0;
@@ -165,7 +166,7 @@ static ssize_t smi_data_read(struct kobject *kobj, char *buf, loff_t pos,
        ret = min(max_read, count);
        memcpy(buf, smi_data_buf + pos, ret);
 out:
-       up(&smi_data_lock);
+       mutex_unlock(&smi_data_lock);
        return ret;
 }
 
@@ -174,7 +175,10 @@ static ssize_t smi_data_write(struct kobject *kobj, char *buf, loff_t pos,
 {
        ssize_t ret;
 
-       down(&smi_data_lock);
+       if ((pos + count) > MAX_SMI_DATA_BUF_SIZE)
+               return -EINVAL;
+
+       mutex_lock(&smi_data_lock);
 
        ret = smi_data_buf_realloc(pos + count);
        if (ret)
@@ -183,7 +187,7 @@ static ssize_t smi_data_write(struct kobject *kobj, char *buf, loff_t pos,
        memcpy(smi_data_buf + pos, buf, count);
        ret = count;
 out:
-       up(&smi_data_lock);
+       mutex_unlock(&smi_data_lock);
        return ret;
 }
 
@@ -201,9 +205,9 @@ static ssize_t host_control_action_store(struct device *dev,
        ssize_t ret;
 
        /* make sure buffer is available for host control command */
-       down(&smi_data_lock);
+       mutex_lock(&smi_data_lock);
        ret = smi_data_buf_realloc(sizeof(struct apm_cmd));
-       up(&smi_data_lock);
+       mutex_unlock(&smi_data_lock);
        if (ret)
                return ret;
 
@@ -302,7 +306,7 @@ static ssize_t smi_request_store(struct device *dev,
        unsigned long val = simple_strtoul(buf, NULL, 10);
        ssize_t ret;
 
-       down(&smi_data_lock);
+       mutex_lock(&smi_data_lock);
 
        if (smi_data_buf_size < sizeof(struct smi_cmd)) {
                ret = -ENODEV;
@@ -334,7 +338,7 @@ static ssize_t smi_request_store(struct device *dev,
        }
 
 out:
-       up(&smi_data_lock);
+       mutex_unlock(&smi_data_lock);
        return ret;
 }
 
@@ -483,26 +487,15 @@ static void dcdbas_host_control(void)
 static int dcdbas_reboot_notify(struct notifier_block *nb, unsigned long code,
                                void *unused)
 {
-       static unsigned int notify_cnt = 0;
-
        switch (code) {
        case SYS_DOWN:
        case SYS_HALT:
        case SYS_POWER_OFF:
                if (host_control_on_shutdown) {
                        /* firmware is going to perform host control action */
-                       if (++notify_cnt == 2) {
-                               printk(KERN_WARNING
-                                      "Please wait for shutdown "
-                                      "action to complete...\n");
-                               dcdbas_host_control();
-                       }
-                       /*
-                        * register again and initiate the host control
-                        * action on the second notification to allow
-                        * everyone that registered to be notified
-                        */
-                       register_reboot_notifier(nb);
+                       printk(KERN_WARNING "Please wait for shutdown "
+                              "action to complete...\n");
+                       dcdbas_host_control();
                }
                break;
        }
@@ -513,7 +506,7 @@ static int dcdbas_reboot_notify(struct notifier_block *nb, unsigned long code,
 static struct notifier_block dcdbas_reboot_nb = {
        .notifier_call = dcdbas_reboot_notify,
        .next = NULL,
-       .priority = 0
+       .priority = INT_MIN
 };
 
 static DCDBAS_BIN_ATTR_RW(smi_data);
@@ -569,7 +562,7 @@ static int __devinit dcdbas_probe(struct platform_device *dev)
                        while (--i >= 0)
                                sysfs_remove_bin_file(&dev->dev.kobj,
                                                      dcdbas_bin_attrs[i]);
-                       sysfs_create_group(&dev->dev.kobj, &dcdbas_attr_group);
+                       sysfs_remove_group(&dev->dev.kobj, &dcdbas_attr_group);
                        return error;
                }
        }