Skip to contentSkip to conversation

nvme-pci: fixing memory leak in probe teardown path

PATCH In review irvin cote 2 participants 2 messages Feb 27, 2023 – Feb 28, 2023 1 message not in the archive NVMe

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): Y/lmo9yfA1w0+Bp2@archlinux

irvin cote

author
#1 lore raw

PATCH 1/1 nvme-pci: fixing memory leak in probe teardown path

---------- Forwarded message ---------
From: Irvin Cote <[email protected]>
Date: Fri, 24 Feb 2023 at 22:38
Subject: [PATCH] nvme-pci: fixing memory leak in probe teardown path
To: <[email protected]>
Cc: <[email protected]>, <[email protected]>, <[email protected]>

In case the nvme_probe teardown path is triggered the ctrl ref count does not reach 0 thus creating a memory leak upon failure of nvme_probe

---
 drivers/nvme/host/pci.c | 1 +
 1 file changed, 1 insertion(+)
drivers/nvme/host/pci.c +0 -0
index 5b95c94ee40f..0b61caf6be67 100644
@@ -3072,6 +3072,7 @@ static int nvme_probe(struct pci_dev *pdev,

const struct pci_device_id *id)
out_dev_unmap:

        nvme_dev_unmap(dev);
 out_uninit_ctrl:
+       nvme_put_ctrl(&dev->ctrl);
        nvme_uninit_ctrl(&dev->ctrl);
        return result;

}
--
2.37.2

maintainer
#2 lore raw
Quoted 21 lines

From: Irvin Cote <[email protected]>
Date: Fri, 24 Feb 2023 at 22:38
Subject: [PATCH] nvme-pci: fixing memory leak in probe teardown path
To: <[email protected]>
Cc: <[email protected]>, <[email protected]>, <[email protected]>

In case the nvme_probe teardown path is triggered the ctrl ref count does not reach 0 thus creating a memory leak upon failure of nvme_probe

---
  drivers/nvme/host/pci.c | 1 +
  1 file changed, 1 insertion(+)
drivers/nvme/host/pci.c +0 -0
index 5b95c94ee40f..0b61caf6be67 100644

drivers/nvme/host/pci.c static int nvme_probe(struct pci_dev *pdev, · line 3077

Quoted 6 lines
drivers/nvme/host/pci.c +1 -0
@@ -3072,6 +3072,7 @@ static int nvme_probe(struct pci_dev *pdev,
 const struct pci_device_id *id)
  out_dev_unmap:
         nvme_dev_unmap(dev);
  out_uninit_ctrl:
+       nvme_put_ctrl(&dev->ctrl);
         nvme_uninit_ctrl(&dev->ctrl);

I'd reverse the order. But looks good.