Commit 23a6b563 authored by Martin Hicks's avatar Martin Hicks Committed by James Bottomley

[PATCH] Call slave_destroy in scsi_alloc_sdev error path

This patch fixes a potential memory leak in scsi_alloc_sdev.

If slave_alloc kmallocs memory and the get_device() (around line 245)
fails then we goto the error path.  The error path never calls
slave_destroy.
parent db0fff74
...@@ -254,7 +254,7 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost, ...@@ -254,7 +254,7 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost,
"%d:%d:%d:%d", sdev->host->host_no, "%d:%d:%d:%d", sdev->host->host_no,
sdev->channel, sdev->id, sdev->lun); sdev->channel, sdev->id, sdev->lun);
} else } else
goto out_free_queue; goto out_cleanup_slave;
/* /*
* If there are any same target siblings, add this to the * If there are any same target siblings, add this to the
...@@ -283,6 +283,9 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost, ...@@ -283,6 +283,9 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost,
spin_unlock_irqrestore(shost->host_lock, flags); spin_unlock_irqrestore(shost->host_lock, flags);
return sdev; return sdev;
out_cleanup_slave:
if (shost->hostt->slave_destroy)
shost->hostt->slave_destroy(sdev);
out_free_queue: out_free_queue:
scsi_free_queue(sdev->request_queue); scsi_free_queue(sdev->request_queue);
out_free_dev: out_free_dev:
......
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