Skip to content

Commit 3719f4f

Browse files
Ming Leimartinkpetersen
authored andcommitted
scsi: core: Fix failure handling of scsi_add_host_with_dma()
When scsi_add_host_with_dma() returns failure, the caller will call scsi_host_put(shost) to release everything allocated for this host instance. Consequently we can't also free allocated stuff in scsi_add_host_with_dma(), otherwise we will end up with a double free. Strictly speaking, host resource allocations should have been done in scsi_host_alloc(). However, the allocations may need information which is not yet provided by the driver when that function is called. So leave the allocations where they are but rely on host device's release handler to free resources. Link: https://lore.kernel.org/r/[email protected] Cc: Bart Van Assche <[email protected]> Cc: John Garry <[email protected]> Cc: Hannes Reinecke <[email protected]> Tested-by: John Garry <[email protected]> Reviewed-by: Bart Van Assche <[email protected]> Reviewed-by: John Garry <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Signed-off-by: Ming Lei <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 66a834d commit 3719f4f

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

drivers/scsi/hosts.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,23 +278,22 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,
278278

279279
if (!shost->work_q) {
280280
error = -EINVAL;
281-
goto out_free_shost_data;
281+
goto out_del_dev;
282282
}
283283
}
284284

285285
error = scsi_sysfs_add_host(shost);
286286
if (error)
287-
goto out_destroy_host;
287+
goto out_del_dev;
288288

289289
scsi_proc_host_add(shost);
290290
scsi_autopm_put_host(shost);
291291
return error;
292292

293-
out_destroy_host:
294-
if (shost->work_q)
295-
destroy_workqueue(shost->work_q);
296-
out_free_shost_data:
297-
kfree(shost->shost_data);
293+
/*
294+
* Any host allocation in this function will be freed in
295+
* scsi_host_dev_release().
296+
*/
298297
out_del_dev:
299298
device_del(&shost->shost_dev);
300299
out_del_gendev:
@@ -304,7 +303,6 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,
304303
pm_runtime_disable(&shost->shost_gendev);
305304
pm_runtime_set_suspended(&shost->shost_gendev);
306305
pm_runtime_put_noidle(&shost->shost_gendev);
307-
scsi_mq_destroy_tags(shost);
308306
fail:
309307
return error;
310308
}

0 commit comments

Comments
 (0)