From 0d0fecc5b5bfddb0e67bef985cdeda2eac7ad6d8 Mon Sep 17 00:00:00 2001 From: Pan Xinhui Date: Wed, 9 Dec 2015 18:00:53 +0800 Subject: powerpc/nvram: Fix a memory leak in err path If kmemdup fails, We need kfree *buff* first then return -ENOMEM. Otherwise there is a memory leak. Signed-off-by: Pan Xinhui Reviewed-by: Nathan Fontenot Signed-off-by: Michael Ellerman --- arch/powerpc/kernel/nvram_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch/powerpc') diff --git a/arch/powerpc/kernel/nvram_64.c b/arch/powerpc/kernel/nvram_64.c index 46c3c76f171b..6cd3a45880c0 100644 --- a/arch/powerpc/kernel/nvram_64.c +++ b/arch/powerpc/kernel/nvram_64.c @@ -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) -- cgit v1.2.3