scsi: aacraid: Fix memory leak in fib init path
[pandora-kernel.git] / drivers / scsi / aacraid / commsup.c
index a03ab8e..7a89f44 100644 (file)
@@ -83,12 +83,20 @@ static int fib_map_alloc(struct aac_dev *dev)
 
 void aac_fib_map_free(struct aac_dev *dev)
 {
-       if (dev->hw_fib_va && dev->max_fib_size) {
-               pci_free_consistent(dev->pdev,
-               (dev->max_fib_size *
-               (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB)),
-               dev->hw_fib_va, dev->hw_fib_pa);
-       }
+       size_t alloc_size;
+       size_t fib_size;
+       int num_fibs;
+
+       if(!dev->hw_fib_va || !dev->max_fib_size)
+               return;
+
+       num_fibs = dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB;
+       fib_size = dev->max_fib_size + sizeof(struct aac_fib_xporthdr);
+       alloc_size = fib_size * num_fibs + ALIGN32 - 1;
+
+       pci_free_consistent(dev->pdev, alloc_size, dev->hw_fib_va,
+                                                       dev->hw_fib_pa);
+
        dev->hw_fib_va = NULL;
        dev->hw_fib_pa = 0;
 }
@@ -116,22 +124,20 @@ int aac_fib_setup(struct aac_dev * dev)
        if (i<0)
                return -ENOMEM;
 
-       /* 32 byte alignment for PMC */
-       hw_fib_pa = (dev->hw_fib_pa + (ALIGN32 - 1)) & ~(ALIGN32 - 1);
-       dev->hw_fib_va = (struct hw_fib *)((unsigned char *)dev->hw_fib_va +
-               (hw_fib_pa - dev->hw_fib_pa));
-       dev->hw_fib_pa = hw_fib_pa;
        memset(dev->hw_fib_va, 0,
                (dev->max_fib_size + sizeof(struct aac_fib_xporthdr)) *
                (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB));
 
+       /* 32 byte alignment for PMC */
+       hw_fib_pa = (dev->hw_fib_pa + (ALIGN32 - 1)) & ~(ALIGN32 - 1);
+       hw_fib    = (struct hw_fib *)((unsigned char *)dev->hw_fib_va +
+                                       (hw_fib_pa - dev->hw_fib_pa));
+
        /* add Xport header */
-       dev->hw_fib_va = (struct hw_fib *)((unsigned char *)dev->hw_fib_va +
+       hw_fib = (struct hw_fib *)((unsigned char *)hw_fib +
                sizeof(struct aac_fib_xporthdr));
-       dev->hw_fib_pa += sizeof(struct aac_fib_xporthdr);
+       hw_fib_pa += sizeof(struct aac_fib_xporthdr);
 
-       hw_fib = dev->hw_fib_va;
-       hw_fib_pa = dev->hw_fib_pa;
        /*
         *      Initialise the fibs
         */