Skip to content

Commit 1171402

Browse files
Ming Leimartinkpetersen
authored andcommitted
scsi: core: Put .shost_dev in failure path if host state changes to RUNNING
scsi_host_dev_release() only frees dev_name when host state is SHOST_CREATED. After host state has changed to SHOST_RUNNING, scsi_host_dev_release() no longer cleans up. Fix this by doing a put_device(&shost->shost_dev) in the failure path when host state is SHOST_RUNNING. Move get_device(&shost->shost_gendev) before device_add(&shost->shost_dev) so that scsi_host_cls_release() can do a put on this reference. Link: https://lore.kernel.org/r/20210602133029.2864069-4-ming.lei@redhat.com Cc: Bart Van Assche <bvanassche@acm.org> Cc: Hannes Reinecke <hare@suse.de> Reported-by: John Garry <john.garry@huawei.com> Tested-by: John Garry <john.garry@huawei.com> Reviewed-by: John Garry <john.garry@huawei.com> Reviewed-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 3719f4f commit 1171402

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

drivers/scsi/hosts.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,11 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,
254254

255255
device_enable_async_suspend(&shost->shost_dev);
256256

257+
get_device(&shost->shost_gendev);
257258
error = device_add(&shost->shost_dev);
258259
if (error)
259260
goto out_del_gendev;
260261

261-
get_device(&shost->shost_gendev);
262-
263262
if (shost->transportt->host_size) {
264263
shost->shost_data = kzalloc(shost->transportt->host_size,
265264
GFP_KERNEL);
@@ -297,6 +296,11 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,
297296
out_del_dev:
298297
device_del(&shost->shost_dev);
299298
out_del_gendev:
299+
/*
300+
* Host state is SHOST_RUNNING so we have to explicitly release
301+
* ->shost_dev.
302+
*/
303+
put_device(&shost->shost_dev);
300304
device_del(&shost->shost_gendev);
301305
out_disable_runtime_pm:
302306
device_disable_async_suspend(&shost->shost_gendev);

0 commit comments

Comments
 (0)