two leaks in scsi_alloc_sdev failure paths
If the scsi_alloc_queue or the slave_alloc calls in scsi_alloc_device fail, we forget to release the locally allocated sdev on the failure path.
Coverity #609
drivers/scsi/scsi_scan.c renamed from drivers/scsi/scsi_scan.c~ +3 -1
@@ -252,7 +252,7 @@ static struct scsi_device *scsi_alloc_sd/* release fn is set up in scsi_sysfs_device_initialise, so * have to free and put manually here */ put_device (&starget->dev); - goto out; + goto out_free; } sdev->request_queue->queuedata = sdev;
@@ -278,6 +278,8 @@ static struct scsi_device *scsi_alloc_sd out_device_destroy:transport_destroy_device (&sdev->sdev_gendev);put_device (&sdev->sdev_gendev); +out_free: +kfree (sdev); out:if (display_failure_msg)printk (ALLOC_FAILURE_MSG , __FUNCTION__);
Signature · 1 line
http://www.codemonkey.org.uk
Quoted 2 lines · Dave Jones
If the
scsi_alloc_queueor theslave_alloccalls inscsi_alloc_devicefail, we forget to release the locally allocated sdev on the failure path.
Actually, I think the slave_alloc failure path works today, and this patch breaks it. Today, in the slave_alloc failure path, the release function called as a result of the put_device in out_device_destroy should end up freeing the sdev. Your patch will result in a double free in this path.
drivers/scsi/scsi_scan.c static struct scsi_device *scsi_alloc_sd · line 255
Quoted 8 lines
drivers/scsi/scsi_scan.c renamed from drivers/scsi/scsi_scan.c~ +1
-1@@ -252,7 +252,7 @@ static struct scsi_device *scsi_alloc_sd/* release fn is set up in scsi_sysfs_device_initialise, so * have to free and put manually here */ put_device (&starget->dev); - goto out; + goto out_free;
Rather than this change, I think just adding a kfree(sdev) before the goto out would accomplish what you want.
Brian
Signature · 3 lines
Brian King eServer Storage I/O IBM Linux Technology Center
Quoted 9 lines · Brian King
Quoted 2 lines · Dave Jones
If the
scsi_alloc_queueor theslave_alloccalls inscsi_alloc_devicefail, we forget to release the locally allocated sdev on the failure path.Actually, I think the
slave_allocfailure path works today, and this patch breaks it. Today, in theslave_allocfailure path, the release function called
as a result of theput_deviceinout_device_destroyshould end up freeing the sdev.
Correct, thanks.
Quoted 2 lines
Rather than this change, I think just adding a kfree(sdev) before the goto out would accomplish what you want.
looks a lot simpler.
Thanks.
Dave
If the scsi_alloc_queue or the slave_alloc calls in scsi_alloc_device fail, we forget to release the locally allocated sdev on the failure path.
Coverity #609
drivers/scsi/scsi_scan.c renamed from drivers/scsi/scsi_scan.c~ +1 -0
@@ -252,6 +252,7 @@ static struct scsi_device *scsi_alloc_sd/* release fn is set up in scsi_sysfs_device_initialise, so * have to free and put manually here */ put_device (&starget->dev); +kfree (sdev); goto out; }
Signature · 1 line
http://www.codemonkey.org.uk