Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752665AbbF2HNw (ORCPT ); Mon, 29 Jun 2015 03:13:52 -0400 Received: from mga11.intel.com ([192.55.52.93]:8649 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750823AbbF2HNq (ORCPT ); Mon, 29 Jun 2015 03:13:46 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,697,1427785200"; d="scan'208";a="719412224" Message-ID: <5590F026.1020202@linux.intel.com> Date: Mon, 29 Jun 2015 15:13:42 +0800 From: Jiang Liu Organization: Intel User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Maninder Singh , rjw@rjwysocki.net, lenb@kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org CC: pankaj.m@samsung.com Subject: Re: [PATCH 1/1] ACPI/resource.c: Fixing memory leak for reg References: <1435559640-18059-1-git-send-email-maninder1.s@samsung.com> In-Reply-To: <1435559640-18059-1-git-send-email-maninder1.s@samsung.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1591 Lines: 50 On 2015/6/29 14:34, Maninder Singh wrote: > static analysis gives memory leak error for reg:- > [drivers/acpi/resource.c:663]: (error) Memory leak: reg > > Thus to prevent this allocate memory for reg after > request_range error checking. Hi Maninder, Seems it would be better to release the allocated memory instead of reorder the code in case of failure. Otherwise the resource region reserved by request_range() will get lost and causes inconsistent view. Thanks! Gerry > > Signed-off-by: Maninder Singh > Reviewed-by: Akhilesh Kumar > --- > drivers/acpi/resource.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c > index fcb7807..f942b70 100644 > --- a/drivers/acpi/resource.c > +++ b/drivers/acpi/resource.c > @@ -655,14 +655,14 @@ static int add_region_before(u64 start, u64 end, u8 space_id, > struct reserved_region *reg; > int error; > > - reg = kmalloc(sizeof(*reg), GFP_KERNEL); > - if (!reg) > - return -ENOMEM; > - > error = request_range(start, end, space_id, flags, desc); > if (error) > return error; > > + reg = kmalloc(sizeof(*reg), GFP_KERNEL); > + if (!reg) > + return -ENOMEM; > + > reg->start = start; > reg->end = end; > list_add_tail(®->node, head); > -- 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/