Commit 56876195 authored by Jesper Juhl's avatar Jesper Juhl Committed by James Bottomley

[SCSI] mpt fusion: fix two potential mem leaks

The Coverity checker spotted two potential memory leaks in
drivers/message/fusion/mptbase.c::mpt_attach().

There are two returns that may leak the storage allocated for 'ioc'
(sizeof(MPT_ADAPTER) bytes).

A simple fix would be to simply add two kfree() calls before the return
statements, but a better fix (that this patch implements) is to reorder the
code so that if we hit the first return condition we don't have to do the
allocation at all and then just add a kfree() call for the second case.
Signed-off-by: default avatarJesper Juhl <jesper.juhl@gmail.com>
Acked-by: default avatar"Moore, Eric Dean" <Eric.Moore@lsil.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@SteelEye.com>
parent d7383a23
...@@ -1458,18 +1458,18 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id) ...@@ -1458,18 +1458,18 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
struct proc_dir_entry *dent, *ent; struct proc_dir_entry *dent, *ent;
#endif #endif
if (mpt_debug_level)
printk(KERN_INFO MYNAM ": mpt_debug_level=%xh\n", mpt_debug_level);
if (pci_enable_device(pdev))
return r;
ioc = kzalloc(sizeof(MPT_ADAPTER), GFP_ATOMIC); ioc = kzalloc(sizeof(MPT_ADAPTER), GFP_ATOMIC);
if (ioc == NULL) { if (ioc == NULL) {
printk(KERN_ERR MYNAM ": ERROR - Insufficient memory to add adapter!\n"); printk(KERN_ERR MYNAM ": ERROR - Insufficient memory to add adapter!\n");
return -ENOMEM; return -ENOMEM;
} }
ioc->debug_level = mpt_debug_level; ioc->debug_level = mpt_debug_level;
if (mpt_debug_level)
printk(KERN_INFO MYNAM ": mpt_debug_level=%xh\n", mpt_debug_level);
if (pci_enable_device(pdev))
return r;
dinitprintk(ioc, printk(KERN_WARNING MYNAM ": mpt_adapter_install\n")); dinitprintk(ioc, printk(KERN_WARNING MYNAM ": mpt_adapter_install\n"));
...@@ -1478,6 +1478,7 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id) ...@@ -1478,6 +1478,7 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
": 64 BIT PCI BUS DMA ADDRESSING SUPPORTED\n")); ": 64 BIT PCI BUS DMA ADDRESSING SUPPORTED\n"));
} else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) { } else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
printk(KERN_WARNING MYNAM ": 32 BIT PCI BUS DMA ADDRESSING NOT SUPPORTED\n"); printk(KERN_WARNING MYNAM ": 32 BIT PCI BUS DMA ADDRESSING NOT SUPPORTED\n");
kfree(ioc);
return r; return r;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment