[PATCH] nvme-pci: After the memory is released, the corresponding pointer needs to point to empty

Liu Jing liujing at cmss.chinamobile.com
Mon Oct 21 12:01:50 PDT 2024


The code frees memory pointed to by dev->queues. After freeing memory,
dev->queues should be set to NULL to avoid dangling Pointers.

Signed-off-by: Liu Jing <liujing at cmss.chinamobile.com>
---
 drivers/nvme/host/pci.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 1cbff7537788..c1500c00f571 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -2731,7 +2731,9 @@ static void nvme_pci_free_ctrl(struct nvme_ctrl *ctrl)
 	nvme_free_tagset(dev);
 	put_device(dev->dev);
 	kfree(dev->queues);
+	dev->queues = NULL;
 	kfree(dev);
+	dev = NULL;
 }
 
 static void nvme_reset_work(struct work_struct *work)
@@ -3055,8 +3057,10 @@ static struct nvme_dev *nvme_pci_alloc_dev(struct pci_dev *pdev,
 out_put_device:
 	put_device(dev->dev);
 	kfree(dev->queues);
+	dev->queues = NULL;
 out_free_dev:
 	kfree(dev);
+	dev = NULL;
 	return ERR_PTR(ret);
 }
 
-- 
2.27.0






More information about the Linux-nvme mailing list