Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 06383f10 authored by Mark Rustad's avatar Mark Rustad Committed by Nicholas Bellinger
Browse files

tcm_fc: Do not free tpg structure during wq allocation failure



Avoid freeing a registered tpg structure if an alloc_workqueue call
fails.  This fixes a bug where the failure was leaking memory associated
with se_portal_group setup during the original core_tpg_register() call.

Signed-off-by: default avatarMark Rustad <mark.d.rustad@intel.com>
Acked-by: default avatarKiran Patil <Kiran.patil@intel.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent e1c40382
Loading
Loading
Loading
Loading
+8 −5
Original line number Original line Diff line number Diff line
@@ -300,6 +300,7 @@ static struct se_portal_group *ft_add_tpg(
{
{
	struct ft_lport_acl *lacl;
	struct ft_lport_acl *lacl;
	struct ft_tpg *tpg;
	struct ft_tpg *tpg;
	struct workqueue_struct *wq;
	unsigned long index;
	unsigned long index;
	int ret;
	int ret;


@@ -321,18 +322,20 @@ static struct se_portal_group *ft_add_tpg(
	tpg->lport_acl = lacl;
	tpg->lport_acl = lacl;
	INIT_LIST_HEAD(&tpg->lun_list);
	INIT_LIST_HEAD(&tpg->lun_list);


	ret = core_tpg_register(&ft_configfs->tf_ops, wwn, &tpg->se_tpg,
	wq = alloc_workqueue("tcm_fc", 0, 1);
				tpg, TRANSPORT_TPG_TYPE_NORMAL);
	if (!wq) {
	if (ret < 0) {
		kfree(tpg);
		kfree(tpg);
		return NULL;
		return NULL;
	}
	}


	tpg->workqueue = alloc_workqueue("tcm_fc", 0, 1);
	ret = core_tpg_register(&ft_configfs->tf_ops, wwn, &tpg->se_tpg,
	if (!tpg->workqueue) {
				tpg, TRANSPORT_TPG_TYPE_NORMAL);
	if (ret < 0) {
		destroy_workqueue(wq);
		kfree(tpg);
		kfree(tpg);
		return NULL;
		return NULL;
	}
	}
	tpg->workqueue = wq;


	mutex_lock(&ft_lport_lock);
	mutex_lock(&ft_lport_lock);
	list_add_tail(&tpg->list, &lacl->tpg_list);
	list_add_tail(&tpg->list, &lacl->tpg_list);