Commit cd58ad7d188c643cf572b038909c2f7dd96fdafe
Committed by
Matthew Wilcox
1 parent
0ac13140d7
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
NVMe: Use ida for nvme device instance
Signed-off-by: Quoc-Son Anh <quoc-sonx.anh@intel.com> Signed-off-by: Matthew Wilcox <matthew.r.wilcox@intel.com>
Showing 1 changed file with 26 additions and 5 deletions Side-by-side Diff
drivers/block/nvme.c
... | ... | @@ -1576,15 +1576,33 @@ |
1576 | 1576 | dma_pool_destroy(dev->prp_small_pool); |
1577 | 1577 | } |
1578 | 1578 | |
1579 | -/* XXX: Use an ida or something to let remove / add work correctly */ | |
1580 | -static void nvme_set_instance(struct nvme_dev *dev) | |
1579 | +static DEFINE_IDA(nvme_instance_ida); | |
1580 | + | |
1581 | +static int nvme_set_instance(struct nvme_dev *dev) | |
1581 | 1582 | { |
1582 | - static int instance; | |
1583 | - dev->instance = instance++; | |
1583 | + int instance, error; | |
1584 | + | |
1585 | + do { | |
1586 | + if (!ida_pre_get(&nvme_instance_ida, GFP_KERNEL)) | |
1587 | + return -ENODEV; | |
1588 | + | |
1589 | + spin_lock(&dev_list_lock); | |
1590 | + error = ida_get_new(&nvme_instance_ida, &instance); | |
1591 | + spin_unlock(&dev_list_lock); | |
1592 | + } while (error == -EAGAIN); | |
1593 | + | |
1594 | + if (error) | |
1595 | + return -ENODEV; | |
1596 | + | |
1597 | + dev->instance = instance; | |
1598 | + return 0; | |
1584 | 1599 | } |
1585 | 1600 | |
1586 | 1601 | static void nvme_release_instance(struct nvme_dev *dev) |
1587 | 1602 | { |
1603 | + spin_lock(&dev_list_lock); | |
1604 | + ida_remove(&nvme_instance_ida, dev->instance); | |
1605 | + spin_unlock(&dev_list_lock); | |
1588 | 1606 | } |
1589 | 1607 | |
1590 | 1608 | static int __devinit nvme_probe(struct pci_dev *pdev, |
... | ... | @@ -1617,7 +1635,10 @@ |
1617 | 1635 | pci_set_drvdata(pdev, dev); |
1618 | 1636 | dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)); |
1619 | 1637 | dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); |
1620 | - nvme_set_instance(dev); | |
1638 | + result = nvme_set_instance(dev); | |
1639 | + if (result) | |
1640 | + goto disable; | |
1641 | + | |
1621 | 1642 | dev->entry[0].vector = pdev->irq; |
1622 | 1643 | |
1623 | 1644 | result = nvme_setup_prp_pools(dev); |