[Lkw] [PATCH] Add kfree

Lisandro Martinez lisandro.martinez.247 at mi.unc.edu.ar
Fri Sep 15 15:02:11 EDT 2023


Signed-off-by: Lisandro Martinez <lisandro.martinez.247 at mi.unc.edu.ar>
---
 drivers/block/nvme-cmb.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/block/nvme-cmb.c b/drivers/block/nvme-cmb.c
index 013331110..534071c4c 100644
--- a/drivers/block/nvme-cmb.c
+++ b/drivers/block/nvme-cmb.c
@@ -1,4 +1,4 @@
-#include <linux/module.h> 
+#include <linux/module.h>
 MODULE_LICENSE("GPL");
 
 #include <linux/init.h>
@@ -6,30 +6,43 @@ MODULE_LICENSE("GPL");
 #include <linux/module.h>
 #include <linux/pci.h>
 
-static int nvme_cmb_probe(struct pci_dev *pdev, const struct pci_device_id *id){
+struct nvme_cmb_dev {
+};
+
+static int nvme_cmb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+{
+	struct nvme_cmb_dev *dev;
 	int error;
 	dev_info(&pdev->dev, "found NVMe device\n");
 
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (!dev)
+		return -ENOMEM;
+       
 	pci_set_master(pdev);
 	error = pci_enable_device_mem(pdev);
 	if (error)
-		return error;
+		goto out_free_dev;
 	error = pci_request_mem_regions(pdev, "nvme-cmb");
 	if (error)
 		goto out_disable_device;
+	dev_set_drvdata(&pdev->dev, dev);
 	return 0;
 
 out_disable_device:
 	pci_disable_device(pdev);
+out_free_dev:
+	kfree(dev);
 	return error;
-
 }
 
 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");
 	pci_release_mem_regions(pdev);
 	pci_disable_device(pdev);
+	kfree(dev);
 }
 
 static const struct pci_device_id nvme_cmb_id_table[] = {
-- 
2.39.2




More information about the LKW mailing list