]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
bnx2x: Fix mem leak in bnx2x_tpa_stop() if build_skb() fails.
authorJesper Juhl <jj@chaosbits.net>
Mon, 6 Feb 2012 11:28:21 +0000 (11:28 +0000)
committerJoe Jin <joe.jin@oracle.com>
Wed, 16 May 2012 14:43:12 +0000 (22:43 +0800)
We allocate memory for 'new_data' with kmalloc(). If we get the memory
we then try to build_skb() and if that should fail (which it can) we
do not enter 'if (likely(skb)) {' and actually use 'new_data' but
instead fall through to the 'drop:' label and end up returning from
the function without ever assigning 'new'data' to anything or freeing
it. That leaks the memory allocated to 'new_data'.

This patch fixes the memory leak by doing a kfree(new_data) in the
case where build_skb() fails (or where allocation of 'new_data' itself
fails, but in taht case it's just a harmless kfree(NULL)).

(cherry picked from commit 3f61cd879c2f112c468e8849949b6fc88c739679)
Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Acked-by: Eric Dumazet <eric.dumazet@gmail.com>
Acked-by: Eilon Greenstein <eilong@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Joe Jin <joe.jin@oracle.com>
drivers/net/bnx2x/bnx2x_cmn.c

index ab0992a8cc640faa7ab933bd641f7a8b7672614f..ba8dd31f6f95ee4c68a012f423af3c35a953ca45 100644 (file)
@@ -511,7 +511,6 @@ static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
                skb = build_skb(data);
 
        if (likely(skb)) {
-
 #ifdef BNX2X_STOP_ON_ERROR
                if (pad + len > fp->rx_buf_size) {
                        BNX2X_ERR("skb_put is about to fail...  "
@@ -545,7 +544,7 @@ static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
 
                return;
        }
-
+       kfree(new_data);
 drop:
        /* drop the packet and keep the buffer in the bin */
        DP(NETIF_MSG_RX_STATUS,