[PATCH] NVMe: Free allocated memory in probe failure

Matthew Wilcox willy at linux.intel.com
Wed May 1 15:49:47 EDT 2013


On Wed, May 01, 2013 at 01:07:50PM -0600, Keith Busch wrote:
> When initializing in probe fails, free only the allocated memory.

'dev'is allocated using kzalloc, and kfree(NULL) is defined to be a no-op.
So having one 'free' label that frees all the memory is fine.

>  	dev->entry = kcalloc(num_possible_cpus(), sizeof(*dev->entry),
>  								GFP_KERNEL);
>  	if (!dev->entry)
> -		goto free;
> +		goto free_dev;
>  	dev->queues = kcalloc(num_possible_cpus() + 1, sizeof(void *),
>  								GFP_KERNEL);
>  	if (!dev->queues)
> -		goto free;
> +		goto free_entry;
>  
>  	if (pci_enable_device_mem(pdev))
>  		goto free;
> @@ -1781,7 +1781,9 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>  	pci_release_regions(pdev);
>   free:
>  	kfree(dev->queues);
> + free_entry:
>  	kfree(dev->entry);
> + free_dev:
>  	kfree(dev);



More information about the Linux-nvme mailing list