Skip to content

Commit 5ee9dce

Browse files
Yang Yingliangsmb49
authored andcommitted
scsi: target: tcm_loop: Fix possible name leak in tcm_loop_setup_hba_bus()
BugLink: https://bugs.launchpad.net/bugs/2002347 [ Upstream commit bc68e42 ] 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: 3703b2c ("[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> Signed-off-by: Kamal Mostafa <kamal@canonical.com> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
1 parent b841d4f commit 5ee9dce

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/target/loopback/tcm_loop.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ static int tcm_loop_setup_hba_bus(struct tcm_loop_hba *tl_hba, int tcm_loop_host
394394
ret = device_register(&tl_hba->dev);
395395
if (ret) {
396396
pr_err("device_register() failed for tl_hba->dev: %d\n", ret);
397+
put_device(&tl_hba->dev);
397398
return -ENODEV;
398399
}
399400

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

10771078
sh = tl_hba->sh;
10781079
tcm_loop_hba_no_cnt++;

0 commit comments

Comments
 (0)