Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] NVMe : Corrected memory freeing.
@ 2015-06-17 16:10 Dheepthi K
  2015-06-17 16:24 ` Matthew Wilcox
  2015-06-17 16:24 ` Keith Busch
  0 siblings, 2 replies; 3+ messages in thread
From: Dheepthi K @ 2015-06-17 16:10 UTC (permalink / raw)


Memory freeing order has been corrected incase of
allocation failure.

Signed-off-by: Dheepthi K <dheepthi.s at gracelabs.com>
---
 drivers/block/nvme-core.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
index 683dff2..9bac53b 100644
--- a/drivers/block/nvme-core.c
+++ b/drivers/block/nvme-core.c
@@ -2947,11 +2947,11 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	dev->entry = kzalloc_node(num_possible_cpus() * sizeof(*dev->entry),
 							GFP_KERNEL, node);
 	if (!dev->entry)
-		goto free;
+		goto free_dev;
 	dev->queues = kzalloc_node((num_possible_cpus() + 1) * sizeof(void *),
 							GFP_KERNEL, node);
 	if (!dev->queues)
-		goto free;
+		goto free_entry;
 
 	INIT_LIST_HEAD(&dev->namespaces);
 	dev->reset_workfn = nvme_reset_failed_dev;
@@ -2987,9 +2987,10 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	nvme_release_instance(dev);
  put_pci:
 	pci_dev_put(dev->pci_dev);
- free:
 	kfree(dev->queues);
+ free_entry:
 	kfree(dev->entry);
+ free_dev:
 	kfree(dev);
 	return result;
 }
-- 
1.7.9.5

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

* [PATCH 1/1] NVMe : Corrected memory freeing.
  2015-06-17 16:10 [PATCH 1/1] NVMe : Corrected memory freeing Dheepthi K
@ 2015-06-17 16:24 ` Matthew Wilcox
  2015-06-17 16:24 ` Keith Busch
  1 sibling, 0 replies; 3+ messages in thread
From: Matthew Wilcox @ 2015-06-17 16:24 UTC (permalink / raw)


On Wed, Jun 17, 2015@09:40:59PM +0530, Dheepthi K wrote:
> Memory freeing order has been corrected incase of
> allocation failure.

This doesn't fix a bug.  kfree(NULL) is a no-op, and 'dev' is allocated
with kzalloc, so the current error path will call kfree(NULL).

> @@ -2947,11 +2947,11 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>  	dev->entry = kzalloc_node(num_possible_cpus() * sizeof(*dev->entry),
>  							GFP_KERNEL, node);
>  	if (!dev->entry)
> -		goto free;
> +		goto free_dev;
>  	dev->queues = kzalloc_node((num_possible_cpus() + 1) * sizeof(void *),
>  							GFP_KERNEL, node);
>  	if (!dev->queues)
> -		goto free;
> +		goto free_entry;
>  
>  	INIT_LIST_HEAD(&dev->namespaces);
>  	dev->reset_workfn = nvme_reset_failed_dev;
> @@ -2987,9 +2987,10 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>  	nvme_release_instance(dev);
>   put_pci:
>  	pci_dev_put(dev->pci_dev);
> - free:
>  	kfree(dev->queues);
> + free_entry:
>  	kfree(dev->entry);
> + free_dev:
>  	kfree(dev);
>  	return result;
>  }
> -- 
> 1.7.9.5

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

* [PATCH 1/1] NVMe : Corrected memory freeing.
  2015-06-17 16:10 [PATCH 1/1] NVMe : Corrected memory freeing Dheepthi K
  2015-06-17 16:24 ` Matthew Wilcox
@ 2015-06-17 16:24 ` Keith Busch
  1 sibling, 0 replies; 3+ messages in thread
From: Keith Busch @ 2015-06-17 16:24 UTC (permalink / raw)


On Wed, 17 Jun 2015, Dheepthi K wrote:
> Memory freeing order has been corrected incase of
> allocation failure.

This isn't necessary. The nvme_dev is zero'ed on allocation, and
kfree(NULL or (void *)0) is okay to do.


> Signed-off-by: Dheepthi K <dheepthi.s at gracelabs.com>
> ---
> drivers/block/nvme-core.c |    7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
> index 683dff2..9bac53b 100644
> --- a/drivers/block/nvme-core.c
> +++ b/drivers/block/nvme-core.c
> @@ -2947,11 +2947,11 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> 	dev->entry = kzalloc_node(num_possible_cpus() * sizeof(*dev->entry),
> 							GFP_KERNEL, node);
> 	if (!dev->entry)
> -		goto free;
> +		goto free_dev;
> 	dev->queues = kzalloc_node((num_possible_cpus() + 1) * sizeof(void *),
> 							GFP_KERNEL, node);
> 	if (!dev->queues)
> -		goto free;
> +		goto free_entry;
>
> 	INIT_LIST_HEAD(&dev->namespaces);
> 	dev->reset_workfn = nvme_reset_failed_dev;
> @@ -2987,9 +2987,10 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> 	nvme_release_instance(dev);
>  put_pci:
> 	pci_dev_put(dev->pci_dev);
> - free:
> 	kfree(dev->queues);
> + free_entry:
> 	kfree(dev->entry);
> + free_dev:
> 	kfree(dev);
> 	return result;
> }

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

end of thread, other threads:[~2015-06-17 16:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-17 16:10 [PATCH 1/1] NVMe : Corrected memory freeing Dheepthi K
2015-06-17 16:24 ` Matthew Wilcox
2015-06-17 16:24 ` Keith Busch

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