Skip to content

Commit d8ef614

Browse files
axiqiagregkh
authored andcommitted
dmaengine: idxd: fix memory leak in error handling path of idxd_pci_probe
commit 90022b3a6981ec234902be5dbf0f983a12c759fc upstream. Memory allocated for idxd is not freed if an error occurs during idxd_pci_probe(). To fix it, free the allocated memory in the reverse order of allocation before exiting the function in case of an error. Fixes: bfe1d56 ("dmaengine: idxd: Init and probe for Intel data accelerators") 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 64afd9a commit d8ef614

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

drivers/dma/idxd/init.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,17 @@ static void idxd_read_caps(struct idxd_device *idxd)
520520
multi_u64_to_bmap(idxd->opcap_bmap, &idxd->hw.opcap.bits[0], 4);
521521
}
522522

523+
static void idxd_free(struct idxd_device *idxd)
524+
{
525+
if (!idxd)
526+
return;
527+
528+
put_device(idxd_confdev(idxd));
529+
bitmap_free(idxd->opcap_bmap);
530+
ida_free(&idxd_ida, idxd->id);
531+
kfree(idxd);
532+
}
533+
523534
static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_data *data)
524535
{
525536
struct device *dev = &pdev->dev;
@@ -739,7 +750,7 @@ static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
739750
err:
740751
pci_iounmap(pdev, idxd->reg_base);
741752
err_iomap:
742-
put_device(idxd_confdev(idxd));
753+
idxd_free(idxd);
743754
err_idxd_alloc:
744755
pci_disable_device(pdev);
745756
return rc;

0 commit comments

Comments
 (0)