aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorBrian King <brking@us.ibm.com>2006-02-22 15:28:24 -0500
committerJames Bottomley <jejb@mulgrave.il.steeleye.com>2006-02-28 00:38:59 -0500
commit32f95792500794a0a7cce266b7dafb2bee323bf8 (patch)
treef7565bd227ffbb71b72f306de84bb1dca3bd0917 /drivers
parentffedb4522571ac170f941678d138a31bc0884ab4 (diff)
[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: Brian King <brking@us.ibm.com> Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/scsi/scsi_scan.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 84f01fd0c8fd..be14f9d82fde 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -332,6 +332,7 @@ static struct scsi_target *scsi_alloc_target(struct device *parent,
332 + shost->transportt->target_size; 332 + shost->transportt->target_size;
333 struct scsi_target *starget; 333 struct scsi_target *starget;
334 struct scsi_target *found_target; 334 struct scsi_target *found_target;
335 int error;
335 336
336 starget = kzalloc(size, GFP_KERNEL); 337 starget = kzalloc(size, GFP_KERNEL);
337 if (!starget) { 338 if (!starget) {
@@ -361,10 +362,20 @@ static struct scsi_target *scsi_alloc_target(struct device *parent,
361 spin_unlock_irqrestore(shost->host_lock, flags); 362 spin_unlock_irqrestore(shost->host_lock, flags);
362 /* allocate and add */ 363 /* allocate and add */
363 transport_setup_device(dev); 364 transport_setup_device(dev);
364 device_add(dev); 365 error = device_add(dev);
366 if (error) {
367 dev_err(dev, "target device_add failed, error %d\n", error);
368 spin_lock_irqsave(shost->host_lock, flags);
369 list_del_init(&starget->siblings);
370 spin_unlock_irqrestore(shost->host_lock, flags);
371 transport_destroy_device(dev);
372 put_device(parent);
373 kfree(starget);
374 return NULL;
375 }
365 transport_add_device(dev); 376 transport_add_device(dev);
366 if (shost->hostt->target_alloc) { 377 if (shost->hostt->target_alloc) {
367 int error = shost->hostt->target_alloc(starget); 378 error = shost->hostt->target_alloc(starget);
368 379
369 if(error) { 380 if(error) {
370 dev_printk(KERN_ERR, dev, "target allocation failed, error %d\n", error); 381 dev_printk(KERN_ERR, dev, "target allocation failed, error %d\n", error);