Skip to content

Commit 90022b3

Browse files
axiqiavinodkoul
authored andcommitted
dmaengine: idxd: fix memory leak in error handling path of idxd_pci_probe
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: stable@vger.kernel.org Signed-off-by: Shuai Xue <xueshuai@linux.alibaba.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Fenghua Yu <fenghuay@nvidia.com> Link: https://lore.kernel.org/r/20250404120217.48772-8-xueshuai@linux.alibaba.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 46a5cca commit 90022b3

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

590+
static void idxd_free(struct idxd_device *idxd)
591+
{
592+
if (!idxd)
593+
return;
594+
595+
put_device(idxd_confdev(idxd));
596+
bitmap_free(idxd->opcap_bmap);
597+
ida_free(&idxd_ida, idxd->id);
598+
kfree(idxd);
599+
}
600+
590601
static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_data *data)
591602
{
592603
struct device *dev = &pdev->dev;
@@ -1255,7 +1266,7 @@ int idxd_pci_probe_alloc(struct idxd_device *idxd, struct pci_dev *pdev,
12551266
err:
12561267
pci_iounmap(pdev, idxd->reg_base);
12571268
err_iomap:
1258-
put_device(idxd_confdev(idxd));
1269+
idxd_free(idxd);
12591270
err_idxd_alloc:
12601271
pci_disable_device(pdev);
12611272
return rc;

0 commit comments

Comments
 (0)