Skip to content

Commit 06383f1

Browse files
mdrustadNicholas Bellinger
authored andcommitted
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: Mark Rustad <[email protected]> Acked-by: Kiran Patil <[email protected]> Cc: <[email protected]> Signed-off-by: Nicholas Bellinger <[email protected]>
1 parent e1c4038 commit 06383f1

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

drivers/target/tcm_fc/tfc_conf.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ static struct se_portal_group *ft_add_tpg(
300300
{
301301
struct ft_lport_acl *lacl;
302302
struct ft_tpg *tpg;
303+
struct workqueue_struct *wq;
303304
unsigned long index;
304305
int ret;
305306

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

324-
ret = core_tpg_register(&ft_configfs->tf_ops, wwn, &tpg->se_tpg,
325-
tpg, TRANSPORT_TPG_TYPE_NORMAL);
326-
if (ret < 0) {
325+
wq = alloc_workqueue("tcm_fc", 0, 1);
326+
if (!wq) {
327327
kfree(tpg);
328328
return NULL;
329329
}
330330

331-
tpg->workqueue = alloc_workqueue("tcm_fc", 0, 1);
332-
if (!tpg->workqueue) {
331+
ret = core_tpg_register(&ft_configfs->tf_ops, wwn, &tpg->se_tpg,
332+
tpg, TRANSPORT_TPG_TYPE_NORMAL);
333+
if (ret < 0) {
334+
destroy_workqueue(wq);
333335
kfree(tpg);
334336
return NULL;
335337
}
338+
tpg->workqueue = wq;
336339

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

0 commit comments

Comments
 (0)