From: Andrew Morton Fix error-path leak. Cc: Panagiotis Issaris Cc: Paul Mackerras Signed-off-by: Andrew Morton --- drivers/net/ppp_generic.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff -puN drivers/net/ppp_generic.c~ppp-handle-kmalloc-failures-leak-fix drivers/net/ppp_generic.c --- a/drivers/net/ppp_generic.c~ppp-handle-kmalloc-failures-leak-fix +++ a/drivers/net/ppp_generic.c @@ -2710,10 +2710,8 @@ static int cardmap_set(struct cardmap ** do { /* need a new top level */ struct cardmap *np = kzalloc(sizeof(*np), GFP_KERNEL); - if (!np) { - printk(KERN_ERR "PPP: no memory (cardmap)\n"); - return -ENOMEM; - } + if (!np) + goto enomem; np->ptr[0] = p; if (p != NULL) { np->shift = p->shift + CARDMAP_ORDER; @@ -2728,10 +2726,8 @@ static int cardmap_set(struct cardmap ** i = (nr >> p->shift) & CARDMAP_MASK; if (p->ptr[i] == NULL) { struct cardmap *np = kzalloc(sizeof(*np), GFP_KERNEL); - if (!np) { - printk(KERN_ERR "PPP: no memory (cardmap)\n"); - return -ENOMEM; - } + if (!np) + goto enomem; np->shift = p->shift - CARDMAP_ORDER; np->parent = p; p->ptr[i] = np; @@ -2747,6 +2743,10 @@ static int cardmap_set(struct cardmap ** else clear_bit(i, &p->inuse); return 0; +enomem: + printk(KERN_ERR "PPP: no memory (cardmap)\n"); + cardmap_destroy(pmap); + return -ENOMEM; } static unsigned int cardmap_find_first_free(struct cardmap *map) _