[Lkw] [PATCH] Ready #4

Alejandro Gaut alejandrogaut at gmail.com
Fri Sep 15 15:03:40 EDT 2023


---
 drivers/block/nvme-cmb.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/block/nvme-cmb.c b/drivers/block/nvme-cmb.c
index 8802082b7..a188cd780 100644
--- a/drivers/block/nvme-cmb.c
+++ b/drivers/block/nvme-cmb.c
@@ -2,10 +2,12 @@
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/pci.h>
+#include <linux/nvme.h>
 
 MODULE_LICENSE("GPL");
 
 struct nvme_cmb_dev {
+	void __iomem *bar;
 };
 
 static int nvme_cmb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
@@ -27,10 +29,23 @@ static int nvme_cmb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	error = pci_request_mem_regions(pdev, "nvme-cmb");
 	if (error)
 		goto out_disable_device;
-
+	dev->bar = pci_ioremap_bar(pdev, 0);
+	if (!dev->bar) {
+		error = -ENOMEM;
+		goto out_release_regions;
+	}
+
+	if (readl(dev->bar + NVME_REG_CSTS) == ~0) {
+		error = -EIO;
+		goto out_iounmap;
+	}
 	dev_set_drvdata(&pdev->dev, dev);	
 	return 0;
 
+out_iounmap:
+	iounmap(dev->bar);
+out_release_regions:
+	pci_release_mem_regions(pdev);
 out_disable_device:
 	pci_disable_device(pdev);
 out_free_dev:
@@ -43,7 +58,7 @@ static void nvme_cmb_remove(struct pci_dev *pdev)
 {
 struct nvme_cmb_dev *dev = dev_get_drvdata(&pdev->dev);
 	dev_info(&pdev->dev, "unbinding NVMe device\n");
-
+	iounmap(dev->bar);
 	pci_release_mem_regions(pdev);
 	pci_disable_device(pdev);
 	kfree(dev);
-- 
2.39.2




More information about the LKW mailing list