Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp5463053rwb; Wed, 17 Aug 2022 18:50:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR6DTMo/QlW3Cg08AJtmV2MZmKvADLIz+DuZp0imCveyq4jsQOkDKWs7Co2kT52oWaTZJ+Bd X-Received: by 2002:a17:907:3d90:b0:730:a937:fb04 with SMTP id he16-20020a1709073d9000b00730a937fb04mr474290ejc.176.1660787423153; Wed, 17 Aug 2022 18:50:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660787423; cv=none; d=google.com; s=arc-20160816; b=MvgCafnztHl/lHA0A6kuePcgUu61GS2GfiuTCVOO/EHjLCL00VhNC2PxqtKKz5FaXG vV7X4XMgvG0vO5EB+OCt9OW6sQK4FvQBLuWMTz73ls2Hrg8tabNa+68hLBPPcH8twF8Z BSFlybxN1W7AfapYH8J++KtqazX57HJCjQcLNFYcKPYgg7pUIlGk905w/NBEKStFvGnD oqhKZDRme+pGG4s2y6+ePPhq7o+3F+RQbXiqnknY7x0oKfxUHoDmJzdRX8wcjG4EGj/E GdXTmpVDS6iIg1kiVMoo2DfHNbG8p6UjxKBFTdok6LqBRDRM5zhHkPZWJSAnoqtRUP1t Bazg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=0//QfsiCR6x3kNsy/xJesmsQ+6G2dth88TWQTfYVDWA=; b=UKFNP4LtHIcs4XoZaaKQ5PckBn376XalR7Ohuk4Si5GNCb0buc3mfRGmgI9Cwo+jZy YM7Dv1Zx8Lnna1Wj0ojJKfM/JwVirbHoSz9kYkNHBMJn/68Zj8wAfhke3XRm4i3FaYvd DiEDWGHMmPhdXehhNp1gEHl3LBfMmhz/FeCWZXI2a2TbbmVrtY15qVTtyV2phJDDVzbY PVaLXW9Nt2tufyjlM84YwwdtsOGzaT0pZ4LDPNU2UgRoN0Tl60ae/oBR5QDEY0eoOVS+ z+xs7fYZjPBto7Lkw75ZjNJhvio4va4idIw+1fMUhLQGF8RnUFfyWvTg+YJQ5lfaXWrb RdfA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nc3-20020a1709071c0300b00730d0b86b28si128388ejc.761.2022.08.17.18.49.56; Wed, 17 Aug 2022 18:50:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242650AbiHRBbZ (ORCPT + 99 others); Wed, 17 Aug 2022 21:31:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242646AbiHRBbY (ORCPT ); Wed, 17 Aug 2022 21:31:24 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92C30A1A52 for ; Wed, 17 Aug 2022 18:31:23 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4M7S3w1xjzzGpgH; Thu, 18 Aug 2022 09:29:48 +0800 (CST) Received: from [10.67.110.176] (10.67.110.176) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 18 Aug 2022 09:31:21 +0800 Subject: Re: [PATCH -next] mtd/ftl: Fix memleak in ftl_add_mtd() To: , , , CC: , , , References: <20220715071105.2321311-1-cuigaosheng1@huawei.com> From: cuigaosheng Message-ID: <6733eee6-bfb6-7ee9-1331-2a739520fcd5@huawei.com> Date: Thu, 18 Aug 2022 09:31:20 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <20220715071105.2321311-1-cuigaosheng1@huawei.com> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.110.176] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org PING ?? 2022/7/15 15:11, Gaosheng Cui ะด??: > When add_mtd_blktrans_dev failed, partition's memory will be freed > by kfree, but there are some structure members that are allocated > for memory independently, such as partition->VirtualBlockMap, > partition->EUNInfo, partition->ZferInfo, and partition->bam_cache, > so kfree(partition) may cause memory leaks, using ftl_freepart(partition) > will fix it. > > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") > Signed-off-by: Gaosheng Cui > --- > drivers/mtd/ftl.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c > index f655d2905270..200271bdc7aa 100644 > --- a/drivers/mtd/ftl.c > +++ b/drivers/mtd/ftl.c > @@ -1031,6 +1031,7 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) > partition->mbd.devnum = -1; > if (!add_mtd_blktrans_dev(&partition->mbd)) > return; > + ftl_freepart(partition); > } > > kfree(partition);