Skip to content

Commit b6e44b4

Browse files
Keith BuschChristoph Hellwig
authored andcommitted
nvme-pci: fix memory leak on probe failure
The nvme driver specific structures need to be initialized prior to enabling the generic controller so we can unwind on failure with out using the reference counting callbacks so that 'probe' and 'remove' can be symmetric. The newly added iod_mempool is the only resource that was being allocated out of order, and a failure there would leak the generic controller memory. This patch just moves that allocation above the controller initialization. Fixes: 943e942 ("nvme-pci: limit max IO size and segments to avoid high order allocations") Reported-by: Weiping Zhang <[email protected]> Signed-off-by: Keith Busch <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 70dbcc2 commit b6e44b4

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

drivers/nvme/host/pci.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,11 +2556,6 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
25562556

25572557
quirks |= check_vendor_combination_bug(pdev);
25582558

2559-
result = nvme_init_ctrl(&dev->ctrl, &pdev->dev, &nvme_pci_ctrl_ops,
2560-
quirks);
2561-
if (result)
2562-
goto release_pools;
2563-
25642559
/*
25652560
* Double check that our mempool alloc size will cover the biggest
25662561
* command we support.
@@ -2578,13 +2573,20 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
25782573
goto release_pools;
25792574
}
25802575

2576+
result = nvme_init_ctrl(&dev->ctrl, &pdev->dev, &nvme_pci_ctrl_ops,
2577+
quirks);
2578+
if (result)
2579+
goto release_mempool;
2580+
25812581
dev_info(dev->ctrl.device, "pci function %s\n", dev_name(&pdev->dev));
25822582

25832583
nvme_get_ctrl(&dev->ctrl);
25842584
async_schedule(nvme_async_probe, dev);
25852585

25862586
return 0;
25872587

2588+
release_mempool:
2589+
mempool_destroy(dev->iod_mempool);
25882590
release_pools:
25892591
nvme_release_prp_pools(dev);
25902592
unmap:

0 commit comments

Comments
 (0)