]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commit
scsi: core: Fix error handling of scsi_host_alloc()
authorMing Lei <ming.lei@redhat.com>
Wed, 2 Jun 2021 13:30:26 +0000 (21:30 +0800)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Thu, 15 Jul 2021 17:27:25 +0000 (19:27 +0200)
commita967617d3f5b5da71848ca56d6dbd1b79938b9a0
treea27ca0ee8f35540d10c9dba0c68d9e89a1b0ab82
parent93ac7f87a0db18cd6db0f8a727c9ec8f65ee1782
scsi: core: Fix error handling of scsi_host_alloc()

BugLink: https://bugs.launchpad.net/bugs/1933369
commit 66a834d092930cf41d809c0e989b13cd6f9ca006 upstream.

After device is initialized via device_initialize(), or its name is set via
dev_set_name(), the device has to be freed via put_device().  Otherwise
device name will be leaked because it is allocated dynamically in
dev_set_name().

Fix the leak by replacing kfree() with put_device(). Since
scsi_host_dev_release() properly handles IDA and kthread removal, remove
special-casing these from the error handling as well.

Link: https://lore.kernel.org/r/20210602133029.2864069-2-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: Kelsey Skunberg <kelsey.skunberg@canonical.com>
drivers/scsi/hosts.c