sata_nv: really fix leak
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 sata_nv: really fix leak
- each label used in a goto contains a part of the operation that must be issued. This way both the no-error and the error paths can be checked separately;
- ioremap() failure did not jump on the adequate label;
- host was never freed if a late error heppened;
- use an adequate status code when ioremap() fails;
- probe_ent does not need to be NULL-initialized;
- enable_hotplug() is issued after everything else has succeeded.
Signed-off-by Francois Romieu <[email protected]>
drivers/scsi/sata_nv.c renamed from drivers/scsi/sata_nv.c~sata_nv-fix-leak-really +28 -27
@@ -295,38 +295,37 @@ static int nv_init_one (struct pci_dev * {static int printed_version =0 ;struct nv_host *host; -struct ata_probe_ent *probe_ent =NULL ; +struct ata_probe_ent *probe_ent;int rc;if (!printed_version++) printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); rc =pci_enable_device (pdev); -if (rc) -return rc; +if (rc <0 ) + goto err_out; rc =pci_request_regions (pdev,DRV_NAME ); -if (rc) - goto err_out; +if (rc <0 ) + goto err_out_disable_device; rc =pci_set_dma_mask (pdev,ATA_DMA_MASK ); -if (rc) - goto err_out_regions; +if (rc <0 ) + goto err_out_release_regions; + rc =pci_set_consistent_dma_mask (pdev,ATA_DMA_MASK ); -if (rc) - goto err_out_regions; +if (rc <0 ) + goto err_out_release_regions; + + rc = -ENOMEM ; probe_ent =kmalloc (sizeof (*probe_ent),GFP_KERNEL ); -if (!probe_ent) { - rc = -ENOMEM ; - goto err_out_regions; - } +if (!probe_ent) + goto err_out_release_regions; host =kmalloc (sizeof (struct nv_host ),GFP_KERNEL ); -if (!host) { - rc = -ENOMEM ; +if (!host) goto err_out_free_ent; - } host->host_desc = &nv_device_tbl[ent->driver_data];
@@ -371,8 +370,10 @@ static int nv_init_one (struct pci_dev * probe_ent->mmio_base =ioremap (pci_resource_start (pdev,5 ),pci_resource_len (pdev,5 )); -if (probe_ent->mmio_base ==NULL ) - goto err_out_iounmap; +if (probe_ent->mmio_base ==NULL ) { + rc = -EIO ; + goto err_out_free_host; + } base = (unsigned long )probe_ent->mmio_base;
@@ -390,14 +391,14 @@ static int nv_init_one (struct pci_dev *pci_set_master (pdev); -// Enable hotplug event interrupts. -if (host->host_desc->enable_hotplug) - host->host_desc->enable_hotplug (probe_ent); - rc =ata_device_add (probe_ent);if (rc !=NV_PORTS ) goto err_out_iounmap; +// Enable hotplug event interrupts. +if (host->host_desc->enable_hotplug) + host->host_desc->enable_hotplug (probe_ent); +kfree (probe_ent);return 0 ;
@@ -405,15 +406,15 @@ static int nv_init_one (struct pci_dev * err_out_iounmap:if (host->host_desc->host_flags &NV_HOST_FLAGS_SCR_MMIO )iounmap (probe_ent->mmio_base); - +err_out_free_host: +kfree (host); err_out_free_ent:kfree (probe_ent); - -err_out_regions: +err_out_release_regions:pci_release_regions (pdev); - -err_out: +err_out_disable_device:pci_disable_device (pdev); +err_out:return rc; }
_