]> git.karo-electronics.de Git - linux-beck.git/commitdiff
Staging: sxg: Fix memory leak in case of allocation failure
authorMithlesh Thukral <mithlesh@linsyssoft.com>
Wed, 18 Feb 2009 13:22:18 +0000 (18:52 +0530)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 3 Apr 2009 21:53:12 +0000 (14:53 -0700)
* Fix a memory leak if allocation of skb fails in sxg_fill_descriptor_block.
  In sxg_fill_descriptor_block(), if allocation of skb failed in loop,
  we just came out shouting. This rollbacks all the successful operation
  before skb allocation fails and then returns.

Signed-off-by: LinSysSoft Sahara Team <saharaproj@linsyssoft.com>
Signed-off-by: Mithlesh Thukral <mithlesh@linsyssoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/sxg/sxg.c

index da286f5765cbbdd11517bfc5e2935548bb0db744..9ce3af53c891111afc987b9fb82403ceef47a09a 100644 (file)
@@ -4212,6 +4212,21 @@ static int sxg_fill_descriptor_block(struct adapter_t *adapter,
                  adapter->FreeRcvBufferCount, adapter->AllRcvBlockCount);
        return (STATUS_SUCCESS);
 no_memory:
+       for (; i >= 0 ; i--) {
+               if (RcvDescriptorBlock->Descriptors[i].VirtualAddress) {
+                       RcvDataBufferHdr = (struct sxg_rcv_data_buffer_hdr *)
+                                           RcvDescriptorBlock->Descriptors[i].
+                                                               VirtualAddress;
+                       RcvDescriptorBlock->Descriptors[i].PhysicalAddress =
+                                           (dma_addr_t)NULL;
+                       RcvDescriptorBlock->Descriptors[i].VirtualAddress=NULL;
+               }
+               SXG_FREE_RCV_DATA_BUFFER(adapter, RcvDataBufferHdr);
+       }
+       RcvDescriptorBlockHdr->State = SXG_BUFFER_FREE;
+       SXG_RETURN_CMD(RingZero, RcvRingInfo, RingDescriptorCmd,
+                       RcvDescriptorBlockHdr);
+
        return (-ENOMEM);
 }