Skip to content

Commit 017d401

Browse files
axiqiagregkh
authored andcommitted
dmaengine: idxd: fix memory leak in error handling path of idxd_pci_probe
commit 90022b3 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 868dbce commit 017d401

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
@@ -585,6 +585,17 @@ static void idxd_read_caps(struct idxd_device *idxd)
585585
idxd->hw.iaa_cap.bits = ioread64(idxd->reg_base + IDXD_IAACAP_OFFSET);
586586
}
587587

588+
static void idxd_free(struct idxd_device *idxd)
589+
{
590+
if (!idxd)
591+
return;
592+
593+
put_device(idxd_confdev(idxd));
594+
bitmap_free(idxd->opcap_bmap);
595+
ida_free(&idxd_ida, idxd->id);
596+
kfree(idxd);
597+
}
598+
588599
static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_data *data)
589600
{
590601
struct device *dev = &pdev->dev;
@@ -857,7 +868,7 @@ static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
857868
err:
858869
pci_iounmap(pdev, idxd->reg_base);
859870
err_iomap:
860-
put_device(idxd_confdev(idxd));
871+
idxd_free(idxd);
861872
err_idxd_alloc:
862873
pci_disable_device(pdev);
863874
return rc;

0 commit comments

Comments
 (0)