linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / char / ipmi / ipmi_devintf.c
index e1c9537..7c0684d 100644 (file)
@@ -42,7 +42,7 @@
 #include <linux/slab.h>
 #include <linux/devfs_fs_kernel.h>
 #include <linux/ipmi.h>
-#include <linux/mutex.h>
+#include <asm/semaphore.h>
 #include <linux/init.h>
 #include <linux/device.h>
 #include <linux/compat.h>
@@ -55,7 +55,7 @@ struct ipmi_file_private
        struct file          *file;
        struct fasync_struct *fasync_queue;
        wait_queue_head_t    wait;
-       struct mutex         recv_mutex;
+       struct semaphore     recv_sem;
        int                  default_retries;
        unsigned int         default_retry_time_ms;
 };
@@ -90,7 +90,7 @@ static unsigned int ipmi_poll(struct file *file, poll_table *wait)
 
        spin_lock_irqsave(&priv->recv_msg_lock, flags);
 
-       if (!list_empty(&(priv->recv_msgs)))
+       if (! list_empty(&(priv->recv_msgs)))
                mask |= (POLLIN | POLLRDNORM);
 
        spin_unlock_irqrestore(&priv->recv_msg_lock, flags);
@@ -141,7 +141,7 @@ static int ipmi_open(struct inode *inode, struct file *file)
        INIT_LIST_HEAD(&(priv->recv_msgs));
        init_waitqueue_head(&priv->wait);
        priv->fasync_queue = NULL;
-       mutex_init(&priv->recv_mutex);
+       sema_init(&(priv->recv_sem), 1);
 
        /* Use the low-level defaults. */
        priv->default_retries = -1;
@@ -285,15 +285,15 @@ static int ipmi_ioctl(struct inode  *inode,
                        break;
                }
 
-               /* We claim a mutex because we don't want two
+               /* We claim a semaphore because we don't want two
                    users getting something from the queue at a time.
                    Since we have to release the spinlock before we can
                    copy the data to the user, it's possible another
                    user will grab something from the queue, too.  Then
                    the messages might get out of order if something
                    fails and the message gets put back onto the
-                   queue.  This mutex prevents that problem. */
-               mutex_lock(&priv->recv_mutex);
+                   queue.  This semaphore prevents that problem. */
+               down(&(priv->recv_sem));
 
                /* Grab the message off the list. */
                spin_lock_irqsave(&(priv->recv_msg_lock), flags);
@@ -352,7 +352,7 @@ static int ipmi_ioctl(struct inode  *inode,
                        goto recv_putback_on_err;
                }
 
-               mutex_unlock(&priv->recv_mutex);
+               up(&(priv->recv_sem));
                ipmi_free_recv_msg(msg);
                break;
 
@@ -362,11 +362,11 @@ static int ipmi_ioctl(struct inode  *inode,
                spin_lock_irqsave(&(priv->recv_msg_lock), flags);
                list_add(entry, &(priv->recv_msgs));
                spin_unlock_irqrestore(&(priv->recv_msg_lock), flags);
-               mutex_unlock(&priv->recv_mutex);
+               up(&(priv->recv_sem));
                break;
 
        recv_err:
-               mutex_unlock(&priv->recv_mutex);
+               up(&(priv->recv_sem));
                break;
        }
 
@@ -789,53 +789,21 @@ MODULE_PARM_DESC(ipmi_major, "Sets the major number of the IPMI device.  By"
                 " interface.  Other values will set the major device number"
                 " to that value.");
 
-/* Keep track of the devices that are registered. */
-struct ipmi_reg_list {
-       dev_t            dev;
-       struct list_head link;
-};
-static LIST_HEAD(reg_list);
-static DEFINE_MUTEX(reg_list_mutex);
-
 static struct class *ipmi_class;
 
-static void ipmi_new_smi(int if_num, struct device *device)
+static void ipmi_new_smi(int if_num)
 {
        dev_t dev = MKDEV(ipmi_major, if_num);
-       struct ipmi_reg_list *entry;
 
        devfs_mk_cdev(dev, S_IFCHR | S_IRUSR | S_IWUSR,
                      "ipmidev/%d", if_num);
 
-       entry = kmalloc(sizeof(*entry), GFP_KERNEL);
-       if (!entry) {
-               printk(KERN_ERR "ipmi_devintf: Unable to create the"
-                      " ipmi class device link\n");
-               return;
-       }
-       entry->dev = dev;
-
-       mutex_lock(&reg_list_mutex);
-       class_device_create(ipmi_class, NULL, dev, device, "ipmi%d", if_num);
-       list_add(&entry->link, &reg_list);
-       mutex_unlock(&reg_list_mutex);
+       class_device_create(ipmi_class, NULL, dev, NULL, "ipmi%d", if_num);
 }
 
 static void ipmi_smi_gone(int if_num)
 {
-       dev_t dev = MKDEV(ipmi_major, if_num);
-       struct ipmi_reg_list *entry;
-
-       mutex_lock(&reg_list_mutex);
-       list_for_each_entry(entry, &reg_list, link) {
-               if (entry->dev == dev) {
-                       list_del(&entry->link);
-                       kfree(entry);
-                       break;
-               }
-       }
-       class_device_destroy(ipmi_class, dev);
-       mutex_unlock(&reg_list_mutex);
+       class_device_destroy(ipmi_class, MKDEV(ipmi_major, if_num));
        devfs_remove("ipmidev/%d", if_num);
 }
 
@@ -888,14 +856,6 @@ module_init(init_ipmi_devintf);
 
 static __exit void cleanup_ipmi(void)
 {
-       struct ipmi_reg_list *entry, *entry2;
-       mutex_lock(&reg_list_mutex);
-       list_for_each_entry_safe(entry, entry2, &reg_list, link) {
-               list_del(&entry->link);
-               class_device_destroy(ipmi_class, entry->dev);
-               kfree(entry);
-       }
-       mutex_unlock(&reg_list_mutex);
        class_destroy(ipmi_class);
        ipmi_smi_watcher_unregister(&smi_watcher);
        devfs_remove(DEVICE_NAME);