Skip to content

Commit ed542be

Browse files
Jeff GarzikJames Bottomley
authored andcommitted
[SCSI] raid class: handle component-add errors
Signed-off-by: Jeff Garzik <[email protected]> Signed-off-by: James Bottomley <[email protected]>
1 parent 83aabc1 commit ed542be

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

drivers/scsi/raid_class.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,19 @@ static void raid_component_release(struct class_device *cdev)
215215
kfree(rc);
216216
}
217217

218-
void raid_component_add(struct raid_template *r,struct device *raid_dev,
219-
struct device *component_dev)
218+
int raid_component_add(struct raid_template *r,struct device *raid_dev,
219+
struct device *component_dev)
220220
{
221221
struct class_device *cdev =
222222
attribute_container_find_class_device(&r->raid_attrs.ac,
223223
raid_dev);
224224
struct raid_component *rc;
225225
struct raid_data *rd = class_get_devdata(cdev);
226+
int err;
226227

227228
rc = kzalloc(sizeof(*rc), GFP_KERNEL);
228229
if (!rc)
229-
return;
230+
return -ENOMEM;
230231

231232
INIT_LIST_HEAD(&rc->node);
232233
class_device_initialize(&rc->cdev);
@@ -239,7 +240,18 @@ void raid_component_add(struct raid_template *r,struct device *raid_dev,
239240
list_add_tail(&rc->node, &rd->component_list);
240241
rc->cdev.parent = cdev;
241242
rc->cdev.class = &raid_class.class;
242-
class_device_add(&rc->cdev);
243+
err = class_device_add(&rc->cdev);
244+
if (err)
245+
goto err_out;
246+
247+
return 0;
248+
249+
err_out:
250+
list_del(&rc->node);
251+
rd->component_count--;
252+
put_device(component_dev);
253+
kfree(rc);
254+
return err;
243255
}
244256
EXPORT_SYMBOL(raid_component_add);
245257

include/linux/raid_class.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,6 @@ DEFINE_RAID_ATTRIBUTE(enum raid_state, state)
7777
struct raid_template *raid_class_attach(struct raid_function_template *);
7878
void raid_class_release(struct raid_template *);
7979

80-
void raid_component_add(struct raid_template *, struct device *,
81-
struct device *);
80+
int __must_check raid_component_add(struct raid_template *, struct device *,
81+
struct device *);
82+

0 commit comments

Comments
 (0)