Commit 32f95792 authored by Brian King's avatar Brian King Committed by James Bottomley

[SCSI] scsi: Handle device_add failure in scsi_alloc_target

Fixes scsi to handle device_add failure in scsi_alloc_target.
Without this patch, if this call were to fail, we can oops
when we free the target.
Signed-off-by: default avatarBrian King <brking@us.ibm.com>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@SteelEye.com>
parent ffedb452
...@@ -332,6 +332,7 @@ static struct scsi_target *scsi_alloc_target(struct device *parent, ...@@ -332,6 +332,7 @@ static struct scsi_target *scsi_alloc_target(struct device *parent,
+ shost->transportt->target_size; + shost->transportt->target_size;
struct scsi_target *starget; struct scsi_target *starget;
struct scsi_target *found_target; struct scsi_target *found_target;
int error;
starget = kzalloc(size, GFP_KERNEL); starget = kzalloc(size, GFP_KERNEL);
if (!starget) { if (!starget) {
...@@ -361,10 +362,20 @@ static struct scsi_target *scsi_alloc_target(struct device *parent, ...@@ -361,10 +362,20 @@ static struct scsi_target *scsi_alloc_target(struct device *parent,
spin_unlock_irqrestore(shost->host_lock, flags); spin_unlock_irqrestore(shost->host_lock, flags);
/* allocate and add */ /* allocate and add */
transport_setup_device(dev); transport_setup_device(dev);
device_add(dev); error = device_add(dev);
if (error) {
dev_err(dev, "target device_add failed, error %d\n", error);
spin_lock_irqsave(shost->host_lock, flags);
list_del_init(&starget->siblings);
spin_unlock_irqrestore(shost->host_lock, flags);
transport_destroy_device(dev);
put_device(parent);
kfree(starget);
return NULL;
}
transport_add_device(dev); transport_add_device(dev);
if (shost->hostt->target_alloc) { if (shost->hostt->target_alloc) {
int error = shost->hostt->target_alloc(starget); error = shost->hostt->target_alloc(starget);
if(error) { if(error) {
dev_printk(KERN_ERR, dev, "target allocation failed, error %d\n", error); dev_printk(KERN_ERR, dev, "target allocation failed, error %d\n", error);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment