]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/scsi/raid_class.c
[SCSI] transport_class: BUG if we can't release the attribute container
[linux-2.6-omap-h63xx.git] / drivers / scsi / raid_class.c
index 5b1c12041a4fd054ffb00bed6bb9eefda1665930..52182a744ba652fbee765293f576b37fd4c95b7d 100644 (file)
@@ -115,7 +115,7 @@ static DECLARE_TRANSPORT_CLASS(raid_class,
                               raid_remove,
                               NULL);
 
-static struct {
+static const struct {
        enum raid_state value;
        char            *name;
 } raid_states[] = {
@@ -131,7 +131,7 @@ static const char *raid_state_name(enum raid_state state)
        int i;
        char *name = NULL;
 
-       for (i = 0; i < sizeof(raid_states)/sizeof(raid_states[0]); i++) {
+       for (i = 0; i < ARRAY_SIZE(raid_states); i++) {
                if (raid_states[i].value == state) {
                        name = raid_states[i].name;
                        break;
@@ -148,9 +148,11 @@ static struct {
        { RAID_LEVEL_LINEAR, "linear" },
        { RAID_LEVEL_0, "raid0" },
        { RAID_LEVEL_1, "raid1" },
+       { RAID_LEVEL_10, "raid10" },
        { RAID_LEVEL_3, "raid3" },
        { RAID_LEVEL_4, "raid4" },
        { RAID_LEVEL_5, "raid5" },
+       { RAID_LEVEL_50, "raid50" },
        { RAID_LEVEL_6, "raid6" },
 };
 
@@ -159,7 +161,7 @@ static const char *raid_level_name(enum raid_level level)
        int i;
        char *name = NULL;
 
-       for (i = 0; i < sizeof(raid_levels)/sizeof(raid_levels[0]); i++) {
+       for (i = 0; i < ARRAY_SIZE(raid_levels); i++) {
                if (raid_levels[i].value == level) {
                        name = raid_levels[i].name;
                        break;
@@ -213,18 +215,19 @@ static void raid_component_release(struct class_device *cdev)
        kfree(rc);
 }
 
-void raid_component_add(struct raid_template *r,struct device *raid_dev,
-                       struct device *component_dev)
+int raid_component_add(struct raid_template *r,struct device *raid_dev,
+                      struct device *component_dev)
 {
        struct class_device *cdev =
                attribute_container_find_class_device(&r->raid_attrs.ac,
                                                      raid_dev);
        struct raid_component *rc;
        struct raid_data *rd = class_get_devdata(cdev);
+       int err;
 
        rc = kzalloc(sizeof(*rc), GFP_KERNEL);
        if (!rc)
-               return;
+               return -ENOMEM;
 
        INIT_LIST_HEAD(&rc->node);
        class_device_initialize(&rc->cdev);
@@ -237,7 +240,18 @@ void raid_component_add(struct raid_template *r,struct device *raid_dev,
        list_add_tail(&rc->node, &rd->component_list);
        rc->cdev.parent = cdev;
        rc->cdev.class = &raid_class.class;
-       class_device_add(&rc->cdev);
+       err = class_device_add(&rc->cdev);
+       if (err)
+               goto err_out;
+
+       return 0;
+
+err_out:
+       list_del(&rc->node);
+       rd->component_count--;
+       put_device(component_dev);
+       kfree(rc);
+       return err;
 }
 EXPORT_SYMBOL(raid_component_add);
 
@@ -275,7 +289,7 @@ raid_class_release(struct raid_template *r)
 {
        struct raid_internal *i = to_raid_internal(r);
 
-       attribute_container_unregister(&i->r.raid_attrs.ac);
+       BUG_ON(attribute_container_unregister(&i->r.raid_attrs.ac));
 
        kfree(i);
 }