libata-sff: ap->[last_]ctl are SFF specific
[safe/jmp/linux-2.6] / drivers / misc / enclosure.c
index 789d121..48c84a5 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
+#include <linux/slab.h>
 
 static LIST_HEAD(container_list);
 static DEFINE_MUTEX(container_list_lock);
@@ -238,7 +239,7 @@ static void enclosure_component_release(struct device *dev)
        put_device(dev->parent);
 }
 
-static struct attribute_group *enclosure_groups[];
+static const struct attribute_group *enclosure_groups[];
 
 /**
  * enclosure_component_register - add a particular component to an enclosure
@@ -315,6 +316,9 @@ int enclosure_add_device(struct enclosure_device *edev, int component,
 
        cdev = &edev->component[component];
 
+       if (cdev->dev == dev)
+               return -EEXIST;
+
        if (cdev->dev)
                enclosure_remove_links(cdev);
 
@@ -332,19 +336,25 @@ EXPORT_SYMBOL_GPL(enclosure_add_device);
  * Returns zero on success or an error.
  *
  */
-int enclosure_remove_device(struct enclosure_device *edev, int component)
+int enclosure_remove_device(struct enclosure_device *edev, struct device *dev)
 {
        struct enclosure_component *cdev;
+       int i;
 
-       if (!edev || component >= edev->components)
+       if (!edev || !dev)
                return -EINVAL;
 
-       cdev = &edev->component[component];
-
-       device_del(&cdev->cdev);
-       put_device(cdev->dev);
-       cdev->dev = NULL;
-       return device_add(&cdev->cdev);
+       for (i = 0; i < edev->components; i++) {
+               cdev = &edev->component[i];
+               if (cdev->dev == dev) {
+                       enclosure_remove_links(cdev);
+                       device_del(&cdev->cdev);
+                       put_device(dev);
+                       cdev->dev = NULL;
+                       return device_add(&cdev->cdev);
+               }
+       }
+       return -ENODEV;
 }
 EXPORT_SYMBOL_GPL(enclosure_remove_device);
 
@@ -382,6 +392,7 @@ static const char *const enclosure_status [] = {
        [ENCLOSURE_STATUS_NOT_INSTALLED] = "not installed",
        [ENCLOSURE_STATUS_UNKNOWN] = "unknown",
        [ENCLOSURE_STATUS_UNAVAILABLE] = "unavailable",
+       [ENCLOSURE_STATUS_MAX] = NULL,
 };
 
 static const char *const enclosure_type [] = {
@@ -527,7 +538,7 @@ static struct attribute_group enclosure_group = {
        .attrs = enclosure_component_attrs,
 };
 
-static struct attribute_group *enclosure_groups[] = {
+static const struct attribute_group *enclosure_groups[] = {
        &enclosure_group,
        NULL
 };