Commit b5a2f790 authored by Yang Yingliang's avatar Yang Yingliang Committed by sanglipeng
Browse files

scsi: target: tcm_loop: Fix possible name leak in tcm_loop_setup_hba_bus()

stable inclusion
from stable-v5.10.156
commit 75205f1b47a88c3fac4f30bd7567e89b2887c7fd
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I7MCG1

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=75205f1b47a88c3fac4f30bd7567e89b2887c7fd



--------------------------------

[ Upstream commit bc68e428 ]

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: 3703b2c5 ("[SCSI] tcm_loop: Add multi-fabric Linux/SCSI LLD fabric module")
Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20221115015042.3652261-1-yangyingliang@huawei.com


Reviewed-by: default avatarMike Christie <michael.chritie@oracle.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarsanglipeng <sanglipeng1@jd.com>
parent 1e1c5738
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -394,6 +394,7 @@ static int tcm_loop_setup_hba_bus(struct tcm_loop_hba *tl_hba, int tcm_loop_host
	ret = device_register(&tl_hba->dev);
	if (ret) {
		pr_err("device_register() failed for tl_hba->dev: %d\n", ret);
		put_device(&tl_hba->dev);
		return -ENODEV;
	}

@@ -1072,7 +1073,7 @@ static struct se_wwn *tcm_loop_make_scsi_hba(
	 */
	ret = tcm_loop_setup_hba_bus(tl_hba, tcm_loop_hba_no_cnt);
	if (ret)
		goto out;
		return ERR_PTR(ret);

	sh = tl_hba->sh;
	tcm_loop_hba_no_cnt++;