Blackfin: fix cache Kconfig typo
[safe/jmp/linux-2.6] / drivers / misc / enclosure.c
index 789d121..e9eae4a 100644 (file)
@@ -238,7 +238,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 +315,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 +335,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);
 
@@ -527,7 +536,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
 };