]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
dmaengine: idxd: fix memory leak in error handling path of idxd_pci_probe
authorShuai Xue <xueshuai@linux.alibaba.com>
Fri, 4 Apr 2025 12:02:15 +0000 (20:02 +0800)
committerVinod Koul <vkoul@kernel.org>
Wed, 14 May 2025 13:40:40 +0000 (14:40 +0100)
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: bfe1d56091c1 ("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>
drivers/dma/idxd/init.c

index 302d8983ed8c7b3a135e427eed538fc2f37d5f2d..f2b5b17538c06961e6a6222b24d383e5cb850152 100644 (file)
@@ -587,6 +587,17 @@ static void idxd_read_caps(struct idxd_device *idxd)
                idxd->hw.iaa_cap.bits = ioread64(idxd->reg_base + IDXD_IAACAP_OFFSET);
 }
 
+static void idxd_free(struct idxd_device *idxd)
+{
+       if (!idxd)
+               return;
+
+       put_device(idxd_confdev(idxd));
+       bitmap_free(idxd->opcap_bmap);
+       ida_free(&idxd_ida, idxd->id);
+       kfree(idxd);
+}
+
 static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_data *data)
 {
        struct device *dev = &pdev->dev;
@@ -1255,7 +1266,7 @@ int idxd_pci_probe_alloc(struct idxd_device *idxd, struct pci_dev *pdev,
  err:
        pci_iounmap(pdev, idxd->reg_base);
  err_iomap:
-       put_device(idxd_confdev(idxd));
+       idxd_free(idxd);
  err_idxd_alloc:
        pci_disable_device(pdev);
        return rc;