scsi: target: tcm_loop: Fix possible name leak in tcm_loop_setup_hba_bus()
authorYang Yingliang <yangyingliang@huawei.com>
Tue, 15 Nov 2022 01:50:42 +0000 (09:50 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 26 Nov 2022 08:24:49 +0000 (09:24 +0100)
commita636772988bafab89278e7bb3420d8e8eacfe912
tree1ba46c551578fd5dac2cc7e8b6ac57bcb64fe2fe
parentcb7893c85ea88937df73814714a1b8ed1abeb9ac
scsi: target: tcm_loop: Fix possible name leak in tcm_loop_setup_hba_bus()

[ Upstream commit bc68e428d4963af0201e92159629ab96948f0893 ]

If device_register() fails in tcm_loop_setup_hba_bus(), the name allocated
by dev_set_name() need be freed. As comment of device_register() says, it
should use put_device() to give up the reference in the error path. So fix
this by calling put_device(), then the name can be freed in kobject_cleanup().
The 'tl_hba' will be freed in tcm_loop_release_adapter(), so it don't need
goto error label in this case.

Fixes: 3703b2c5d041 ("[SCSI] tcm_loop: Add multi-fabric Linux/SCSI LLD fabric module")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20221115015042.3652261-1-yangyingliang@huawei.com
Reviewed-by: Mike Christie <michael.chritie@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/target/loopback/tcm_loop.c