[SCSI] raid class: handle component-add errors

Signed-off-by: Jeff Garzik <jeff@garzik.org>
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>

authored by Jeff Garzik and committed by James Bottomley ed542bed 83aabc1b

+19 -6
+16 -4
drivers/scsi/raid_class.c
··· 215 kfree(rc); 216 } 217 218 - void raid_component_add(struct raid_template *r,struct device *raid_dev, 219 - struct device *component_dev) 220 { 221 struct class_device *cdev = 222 attribute_container_find_class_device(&r->raid_attrs.ac, 223 raid_dev); 224 struct raid_component *rc; 225 struct raid_data *rd = class_get_devdata(cdev); 226 227 rc = kzalloc(sizeof(*rc), GFP_KERNEL); 228 if (!rc) 229 - return; 230 231 INIT_LIST_HEAD(&rc->node); 232 class_device_initialize(&rc->cdev); ··· 240 list_add_tail(&rc->node, &rd->component_list); 241 rc->cdev.parent = cdev; 242 rc->cdev.class = &raid_class.class; 243 - class_device_add(&rc->cdev); 244 } 245 EXPORT_SYMBOL(raid_component_add); 246
··· 215 kfree(rc); 216 } 217 218 + int raid_component_add(struct raid_template *r,struct device *raid_dev, 219 + struct device *component_dev) 220 { 221 struct class_device *cdev = 222 attribute_container_find_class_device(&r->raid_attrs.ac, 223 raid_dev); 224 struct raid_component *rc; 225 struct raid_data *rd = class_get_devdata(cdev); 226 + int err; 227 228 rc = kzalloc(sizeof(*rc), GFP_KERNEL); 229 if (!rc) 230 + return -ENOMEM; 231 232 INIT_LIST_HEAD(&rc->node); 233 class_device_initialize(&rc->cdev); ··· 239 list_add_tail(&rc->node, &rd->component_list); 240 rc->cdev.parent = cdev; 241 rc->cdev.class = &raid_class.class; 242 + err = class_device_add(&rc->cdev); 243 + if (err) 244 + goto err_out; 245 + 246 + return 0; 247 + 248 + err_out: 249 + list_del(&rc->node); 250 + rd->component_count--; 251 + put_device(component_dev); 252 + kfree(rc); 253 + return err; 254 } 255 EXPORT_SYMBOL(raid_component_add); 256
+3 -2
include/linux/raid_class.h
··· 77 struct raid_template *raid_class_attach(struct raid_function_template *); 78 void raid_class_release(struct raid_template *); 79 80 - void raid_component_add(struct raid_template *, struct device *, 81 - struct device *);
··· 77 struct raid_template *raid_class_attach(struct raid_function_template *); 78 void raid_class_release(struct raid_template *); 79 80 + int __must_check raid_component_add(struct raid_template *, struct device *, 81 + struct device *); 82 +