]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commit
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)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Thu, 15 Jul 2021 17:24:16 +0000 (19:24 +0200)
commit1ef8f271d5d3ed99234d71b3d7ded09b9dc1115d
treeec01c8cc99df66c017b1de8f9e93b74488310dc4
parentc944a4f0b220c6d3f3ba35752e7a8272e2b3e3ad
scsi: core: Fix failure handling of scsi_add_host_with_dma()

BugLink: https://bugs.launchpad.net/bugs/1934012
commit 3719f4ff047e20062b8314c23ec3cab84d74c908 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
drivers/scsi/hosts.c