[PATCH] fix allocating target in scsi scan

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When allocating target fails NUL is directly returned without making
certain that it already exists.

The uncertainty is fixed by checking already created targets, then
returns the correct.

Signed-off-by: Hillf Danton <dhillf@xxxxxxxxx>
---

--- a/drivers/scsi/scsi_scan.c	2010-09-13 07:07:38.000000000 +0800
+++ b/drivers/scsi/scsi_scan.c	2010-11-03 22:29:34.000000000 +0800
@@ -410,7 +410,7 @@ static struct scsi_target *scsi_alloc_ta
 	starget = kzalloc(size, GFP_KERNEL);
 	if (!starget) {
 		printk(KERN_ERR "%s: allocation failure\n", __func__);
-		return NULL;
+		goto retry;
 	}
 	dev = &starget->dev;
 	device_initialize(dev);
@@ -435,7 +435,10 @@ static struct scsi_target *scsi_alloc_ta
 	found_target = __scsi_find_target(parent, channel, id);
 	if (found_target)
 		goto found;
-
+	if (! dev) {
+		spin_unlock_irqrestore(shost->host_lock, flags);
+		return NULL;
+	}
 	list_add_tail(&starget->siblings, &shost->__targets);
 	spin_unlock_irqrestore(shost->host_lock, flags);
 	/* allocate and add */
@@ -459,14 +462,17 @@ static struct scsi_target *scsi_alloc_ta
 	found_target->reap_ref++;
 	spin_unlock_irqrestore(shost->host_lock, flags);
 	if (found_target->state != STARGET_DEL) {
-		put_device(dev);
+		if (dev)
+			put_device(dev);
 		return found_target;
 	}
 	/* Unfortunately, we found a dying target; need to
 	 * wait until it's dead before we can get a new one */
 	put_device(&found_target->dev);
 	flush_scheduled_work();
-	goto retry;
+	if (dev)
+		goto retry;
+	return NULL;
 }

 static void scsi_target_reap_usercontext(struct work_struct *work)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]
  Powered by Linux