]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
powerpc/nvram: Fix a memory leak in err path
authorPan Xinhui <xinhui.pan@linux.vnet.ibm.com>
Wed, 9 Dec 2015 10:00:53 +0000 (18:00 +0800)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 20 Sep 2016 06:15:33 +0000 (16:15 +1000)
If kmemdup fails, We need kfree *buff* first then return -ENOMEM.
Otherwise there is a memory leak.

Signed-off-by: Pan Xinhui <xinhui.pan@linux.vnet.ibm.com>
Reviewed-by: Nathan Fontenot <nfont@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/kernel/nvram_64.c

index 46c3c76f171b84088c0b819bb95b3386a75679b4..6cd3a45880c09adb2481c9872041218f6ebf1659 100644 (file)
@@ -542,9 +542,9 @@ static ssize_t nvram_pstore_read(u64 *id, enum pstore_type_id *type,
                        time->tv_nsec = 0;
                }
                *buf = kmemdup(buff + hdr_size, length, GFP_KERNEL);
+               kfree(buff);
                if (*buf == NULL)
                        return -ENOMEM;
-               kfree(buff);
 
                *ecc_notice_size = 0;
                if (err_type == ERR_TYPE_KERNEL_PANIC_GZ)