aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/nvme/host/pci.c
diff options
context:
space:
mode:
authorKeith Busch <keith.busch@intel.com>2018-07-11 18:44:44 -0400
committerChristoph Hellwig <hch@lst.de>2018-07-12 02:23:56 -0400
commitb6e44b4c74ef75f729f0147d43d189173fe463c9 (patch)
treed8ae6812233e06ffe1140a44afca7fbe4d5c32ef /drivers/nvme/host/pci.c
parent70dbcc2254fa2a9add74a122b9dac954c4736e01 (diff)
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: 943e942e6266f ("nvme-pci: limit max IO size and segments to avoid high order allocations") Reported-by: Weiping Zhang <zwp10758@gmail.com> Signed-off-by: Keith Busch <keith.busch@intel.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'drivers/nvme/host/pci.c')
-rw-r--r--drivers/nvme/host/pci.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index ba943f211687..ddd441b1516a 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -2556,11 +2556,6 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2556 2556
2557 quirks |= check_vendor_combination_bug(pdev); 2557 quirks |= check_vendor_combination_bug(pdev);
2558 2558
2559 result = nvme_init_ctrl(&dev->ctrl, &pdev->dev, &nvme_pci_ctrl_ops,
2560 quirks);
2561 if (result)
2562 goto release_pools;
2563
2564 /* 2559 /*
2565 * Double check that our mempool alloc size will cover the biggest 2560 * Double check that our mempool alloc size will cover the biggest
2566 * command we support. 2561 * command we support.
@@ -2578,6 +2573,11 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2578 goto release_pools; 2573 goto release_pools;
2579 } 2574 }
2580 2575
2576 result = nvme_init_ctrl(&dev->ctrl, &pdev->dev, &nvme_pci_ctrl_ops,
2577 quirks);
2578 if (result)
2579 goto release_mempool;
2580
2581 dev_info(dev->ctrl.device, "pci function %s\n", dev_name(&pdev->dev)); 2581 dev_info(dev->ctrl.device, "pci function %s\n", dev_name(&pdev->dev));
2582 2582
2583 nvme_get_ctrl(&dev->ctrl); 2583 nvme_get_ctrl(&dev->ctrl);
@@ -2585,6 +2585,8 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2585 2585
2586 return 0; 2586 return 0;
2587 2587
2588 release_mempool:
2589 mempool_destroy(dev->iod_mempool);
2588 release_pools: 2590 release_pools:
2589 nvme_release_prp_pools(dev); 2591 nvme_release_prp_pools(dev);
2590 unmap: 2592 unmap: