scsi: core: Fix failure handling of scsi_add_host_with_dma()
authorMing Lei <ming.lei@redhat.com>
Wed, 2 Jun 2021 13:30:27 +0000 (21:30 +0800)
committerMartin K. Petersen <martin.petersen@oracle.com>
Tue, 8 Jun 2021 02:12:44 +0000 (22:12 -0400)
commit3719f4ff047e20062b8314c23ec3cab84d74c908
treeb1311fbdbf55aa87c1cbdad6613d72d47526edee
parent66a834d092930cf41d809c0e989b13cd6f9ca006
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/20210602133029.2864069-3-ming.lei@redhat.com
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: John Garry <john.garry@huawei.com>
Cc: Hannes Reinecke <hare@suse.de>
Tested-by: John Garry <john.garry@huawei.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
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>
drivers/scsi/hosts.c