Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754319AbbLIXwV (ORCPT ); Wed, 9 Dec 2015 18:52:21 -0500 Received: from e28smtp01.in.ibm.com ([125.16.236.1]:41461 "EHLO e28smtp01.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752090AbbLIXwU (ORCPT ); Wed, 9 Dec 2015 18:52:20 -0500 X-IBM-Helo: d28dlp01.in.ibm.com X-IBM-MailFrom: xinhui@linux.vnet.ibm.com X-IBM-RcptTo: linux-kernel@vger.kernel.org Subject: Re: [PATCH] powerpc/nvram: Fix a memory leak in err path To: Nathan Fontenot , xinhui , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org References: <5667FBD5.2050206@linux.vnet.ibm.com> <566846F5.2020507@linux.vnet.ibm.com> Cc: Andrzej Hajda , Christophe Jaillet , Hari Bathini , Paul Mackerras From: xinhui Message-ID: <5668BEA5.1000002@linux.vnet.ibm.com> Date: Thu, 10 Dec 2015 07:52:05 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <566846F5.2020507@linux.vnet.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15120923-4790-0000-0000-00000C1A0EF3 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1278 Lines: 44 On 2015/12/9 23:21, Nathan Fontenot wrote: > On 12/09/2015 04:00 AM, xinhui wrote: >> >> 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 > Hi Nathan, thank you for doing that :) thanks xinhui >> --- >> arch/powerpc/kernel/nvram_64.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/arch/powerpc/kernel/nvram_64.c b/arch/powerpc/kernel/nvram_64.c >> index 32e2652..21a278b7 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); >> >> if (err_type == ERR_TYPE_KERNEL_PANIC_GZ) >> *compressed = true; >> -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/