From patchwork Mon Nov 23 08:47:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matias Bjorling X-Patchwork-Id: 7678051 X-Patchwork-Delegate: axboe@kernel.dk Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 04A9CBF90C for ; Mon, 23 Nov 2015 08:48:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2E94B20628 for ; Mon, 23 Nov 2015 08:48:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 469E42061D for ; Mon, 23 Nov 2015 08:48:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753920AbbKWIrt (ORCPT ); Mon, 23 Nov 2015 03:47:49 -0500 Received: from mail-wm0-f51.google.com ([74.125.82.51]:36349 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753859AbbKWIrP (ORCPT ); Mon, 23 Nov 2015 03:47:15 -0500 Received: by wmww144 with SMTP id w144so86271000wmw.1 for ; Mon, 23 Nov 2015 00:47:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lightnvm-io.20150623.gappssmtp.com; s=20150623; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=7H2p1x9Pw+H7Q7RvajAgoSwexNf2Cjt47CrXMLCwc7o=; b=c38DNrivGpYgmsLjfdvnN0oZmLHzhS8BVqsGd4ot6I/lp1DWqQ5OmzT9dc7iqUHqXw f2Nd4m4LM8aqpMUiOJs03fKX/OX4o+iNGAauM0sNeFv75nTTRxz6S2MxuYGrBuHS3oCi t7QickhzWmzKb/014a0/dibyJhy/b51JSwbYKW3T45zRC0FvtKr23hjmxA2iDM8CfQp4 T6QXMN/JyL6XcDJX9dfs5njsHzwWDa7KR78mTESD0nKPeuwbdtzY5Fl6j4HifrHXtTyt RQmuqnQ55BN3OuFor8/7ESk0X7MJJL3B5sYXauFn5aJfj6+LNiyknYsxFvTABIGYw/R1 U41A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=7H2p1x9Pw+H7Q7RvajAgoSwexNf2Cjt47CrXMLCwc7o=; b=PHU39YO9h7QDvtrFdo1iKCjzcaaGmYMWLX9fqa4fXxDPZ3h4OqrisSUpNakrxtwby+ 7wDUQfyvtRStXQUn6Rd4AOfGlf2S001NhLlFlAg/BSLqdIlma/4GRGyz4xs6o9xLivwu gLRl0cwRVP6heMVniSZNRWDv7Jd2Rtg2SAhsv4+mxweBVkc8LXXDKOun9+MKcfutrCZU LWzMt1vKX+pFiu9EIy4hcNEPdPc3ArIyzibPTw6h/K9TIoW3R0Nghrt9Y5Nu7Na7jA0S NNUfSih8pHgT2DEV/5iYE4mpz57fsjtd9EkYgnn5psh0PHDAI7QdOSqLVfCvHfPm1cqO zxUQ== X-Gm-Message-State: ALoCoQk4OjFiktPt6EVyRWWplFv/M6wNEWEwDCEa44nkif0XoTVehtAMZjsBBGJqZTN0JZ1549/t X-Received: by 10.194.133.137 with SMTP id pc9mr28956391wjb.162.1448268433977; Mon, 23 Nov 2015 00:47:13 -0800 (PST) Received: from [192.168.1.131] (6164198-cl69.boa.fiberby.dk. [193.106.164.198]) by smtp.googlemail.com with ESMTPSA id s9sm12079890wmf.2.2015.11.23.00.47.13 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 Nov 2015 00:47:13 -0800 (PST) Message-ID: <5652D290.8090705@lightnvm.io> Date: Mon, 23 Nov 2015 09:47:12 +0100 From: =?windows-1252?Q?Matias_Bj=F8rling?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Wenwei Tao CC: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org Subject: Re: [PATCH] lightnvm: free allocated memory when gennvm register fails References: <1448267375-19009-1-git-send-email-ww.tao0320@gmail.com> In-Reply-To: <1448267375-19009-1-git-send-email-ww.tao0320@gmail.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 11/23/2015 09:29 AM, Wenwei Tao wrote: > free allocated nvm block and gennvm lun structures when > gennvm register fails, otherwise it will cause memory leak. > > Signed-off-by: Wenwei Tao > --- > drivers/lightnvm/gennvm.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/lightnvm/gennvm.c b/drivers/lightnvm/gennvm.c > index ae1fb2b..03fc7a5 100644 > --- a/drivers/lightnvm/gennvm.c > +++ b/drivers/lightnvm/gennvm.c > @@ -211,12 +211,15 @@ static int gennvm_register(struct nvm_dev *dev) > ret = gennvm_blocks_init(dev, gn); > if (ret) { > pr_err("gennvm: could not initialize blocks\n"); > + gennvm_blocks_free(dev); > + gennvm_luns_free(dev); > goto err; > } > > return 1; > err: > kfree(gn); > + dev->mp = NULL; > return ret; > } > > Thanks Tao, would it be okay with you if I apply the patch like this: struct gen_nvm *gn; @@ -234,16 +242,13 @@ static int gennvm_register(struct nvm_dev *dev) return 1; err: - kfree(gn); + gennvm_free(dev); return ret; } static void gennvm_unregister(struct nvm_dev *dev) { - gennvm_blocks_free(dev); - gennvm_luns_free(dev); - kfree(dev->mp); - dev->mp = NULL; + gennvm_free(dev); } --- To unsubscribe from this list: send the line "unsubscribe linux-block" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git i/drivers/lightnvm/gennvm.c w/drivers/lightnvm/gennvm.c index e20e74e..3969a98 100644 --- i/drivers/lightnvm/gennvm.c +++ w/drivers/lightnvm/gennvm.c @@ -207,6 +207,14 @@ static int gennvm_blocks_init(struct nvm_dev *dev, struct gen_nvm *gn) return 0; } +static void gennvm_free(struct nvm_dev *dev) +{ + gennvm_blocks_free(dev); + gennvm_luns_free(dev); + kfree(dev->mp); + dev->mp = NULL; +} + static int gennvm_register(struct nvm_dev *dev) {