Skip to content

Commit 868dbce

Browse files
axiqiagregkh
authored andcommitted
dmaengine: idxd: fix memory leak in error handling path of idxd_alloc
commit 46a5cca upstream. Memory allocated for idxd is not freed if an error occurs during idxd_alloc(). To fix it, free the allocated memory in the reverse order of allocation before exiting the function in case of an error. Fixes: a8563a3 ("dmanegine: idxd: reformat opcap output to match bitmap_parse() input") Cc: [email protected] Signed-off-by: Shuai Xue <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Reviewed-by: Fenghua Yu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 21f9f5c commit 868dbce

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

drivers/dma/idxd/init.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -602,28 +602,34 @@ static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_d
602602
idxd_dev_set_type(&idxd->idxd_dev, idxd->data->type);
603603
idxd->id = ida_alloc(&idxd_ida, GFP_KERNEL);
604604
if (idxd->id < 0)
605-
return NULL;
605+
goto err_ida;
606606

607607
idxd->opcap_bmap = bitmap_zalloc_node(IDXD_MAX_OPCAP_BITS, GFP_KERNEL, dev_to_node(dev));
608-
if (!idxd->opcap_bmap) {
609-
ida_free(&idxd_ida, idxd->id);
610-
return NULL;
611-
}
608+
if (!idxd->opcap_bmap)
609+
goto err_opcap;
612610

613611
device_initialize(conf_dev);
614612
conf_dev->parent = dev;
615613
conf_dev->bus = &dsa_bus_type;
616614
conf_dev->type = idxd->data->dev_type;
617615
rc = dev_set_name(conf_dev, "%s%d", idxd->data->name_prefix, idxd->id);
618-
if (rc < 0) {
619-
put_device(conf_dev);
620-
return NULL;
621-
}
616+
if (rc < 0)
617+
goto err_name;
622618

623619
spin_lock_init(&idxd->dev_lock);
624620
spin_lock_init(&idxd->cmd_lock);
625621

626622
return idxd;
623+
624+
err_name:
625+
put_device(conf_dev);
626+
bitmap_free(idxd->opcap_bmap);
627+
err_opcap:
628+
ida_free(&idxd_ida, idxd->id);
629+
err_ida:
630+
kfree(idxd);
631+
632+
return NULL;
627633
}
628634

629635
static int idxd_enable_system_pasid(struct idxd_device *idxd)

0 commit comments

Comments
 (0)