public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme-pci: After the memory is released, the corresponding pointer needs to point to empty
@ 2024-10-21 19:01 Liu Jing
  2024-10-22  7:29 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Liu Jing @ 2024-10-21 19:01 UTC (permalink / raw)
  To: kbusch; +Cc: axboe, hch, sagi, linux-nvme, linux-kernel, Liu Jing

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@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




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] nvme-pci: After the memory is released, the corresponding pointer needs to point to empty
  2024-10-21 19:01 [PATCH] nvme-pci: After the memory is released, the corresponding pointer needs to point to empty Liu Jing
@ 2024-10-22  7:29 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2024-10-22  7:29 UTC (permalink / raw)
  To: Liu Jing; +Cc: kbusch, axboe, hch, sagi, linux-nvme, linux-kernel

On Tue, Oct 22, 2024 at 03:01:50AM +0800, Liu Jing wrote:
> The code frees memory pointed to by dev->queues. After freeing memory,
> dev->queues should be set to NULL to avoid dangling Pointers.

How claims that?  Clearing pointers clearly defeats redzoning in the
slab allocator so actually is counterproductive.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-10-22  7:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-21 19:01 [PATCH] nvme-pci: After the memory is released, the corresponding pointer needs to point to empty Liu Jing
2024-10-22  7:29 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox