Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp123136rwb; Thu, 18 Aug 2022 00:21:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR6zaVkc1v+YFu8gQyj5iaLXyMUbwZVCDecWDXNcmRKprwbPGFSh4zg0ghMMuHAFehP3F1b3 X-Received: by 2002:a17:902:d48f:b0:16f:a73:bf04 with SMTP id c15-20020a170902d48f00b0016f0a73bf04mr1515295plg.43.1660807302261; Thu, 18 Aug 2022 00:21:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660807302; cv=none; d=google.com; s=arc-20160816; b=kwHGgL8UsVsXoLkSuzebHXShzUF/BJ+8Z0CEniyJ+2zUpXHWGxvyZZz4h59vC0yvoJ rIAEfVyswB5L8kS+d/JfCMQw155VF/qsbHEYbbzLf8rTel7rac5FCaP6LvtV1L4jcrKy /MytdlMfsPjOX+59fzsICe6ujHWeJlT7+AxfilW/ChCUTtaJ74glPveh+rqdR0+GCILx ai5XOaYPcNwHyq13vXJpHipWGKVhfxnfoL9kfOzIePBXv9FMg9Ped+vwb+jAiKsuGyjU 0sCi+EUoCFoXcTtz6tuGTMUH2aBjYU8E+N3vUX2yK9dQnZqqapkjkCssfc4VA7TWAJwW 3MdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date; bh=uxvP4ojvb3auBJ96ME5Sy3B6/EAoKzUECRGXiT9E4f8=; b=pkGHdyKLYckx5MOX44ddpINS9zYJXF5XU4POBVn0WjvQ9buqI+Z+tfMLZ3RYze3Ixz h4ll58kwCzM0VsYPm7U4YboNPe68gcbGBzYQOACIxAFF0QxKLfRnVCeA4hbyVU6flg0l mMfJQkmq5C4jqpCVM55Rcimajssa/cKwL2NPzo3x5uTnAb4QJSjFlcMC21wPKhsGMW8+ FpLhaRgH1O9R+QFvoMOKjfc7HVSPHEJXkiR60cOIIropeB8LWdWaeKip4l9Alzb32eiA Ln7nKgZnirl1sfZxtxvy5x3InyzQj/O462ttLSX+3H6fnH0JZzl/wVjOz6mAVDrDJ6zf eHSg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u9-20020a170903124900b001726d843055si750719plh.378.2022.08.18.00.21.31; Thu, 18 Aug 2022 00:21:42 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243112AbiHRG7j convert rfc822-to-8bit (ORCPT + 99 others); Thu, 18 Aug 2022 02:59:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239022AbiHRG7d (ORCPT ); Thu, 18 Aug 2022 02:59:33 -0400 Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B01B6EF0E for ; Wed, 17 Aug 2022 23:59:30 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id AB65D61F1132; Thu, 18 Aug 2022 08:59:28 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id B7xKpa3dEKri; Thu, 18 Aug 2022 08:59:28 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 45B1F61F113A; Thu, 18 Aug 2022 08:59:28 +0200 (CEST) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id I6RGV6UGPG4Y; Thu, 18 Aug 2022 08:59:28 +0200 (CEST) Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) by lithops.sigma-star.at (Postfix) with ESMTP id 23A6A61F1132; Thu, 18 Aug 2022 08:59:28 +0200 (CEST) Date: Thu, 18 Aug 2022 08:59:27 +0200 (CEST) From: Richard Weinberger To: cuigaosheng Cc: Miquel Raynal , Vignesh Raghavendra , linux-mtd , linux-kernel , gongruiqi1@huawei.com, wangweiyang2@huawei.com Message-ID: <1160016027.119085.1660805967979.JavaMail.zimbra@nod.at> In-Reply-To: <6733eee6-bfb6-7ee9-1331-2a739520fcd5@huawei.com> References: <20220715071105.2321311-1-cuigaosheng1@huawei.com> <6733eee6-bfb6-7ee9-1331-2a739520fcd5@huawei.com> Subject: Re: [PATCH -next] mtd/ftl: Fix memleak in ftl_add_mtd() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT X-Originating-IP: [195.201.40.130] X-Mailer: Zimbra 8.8.12_GA_3807 (ZimbraWebClient - FF97 (Linux)/8.8.12_GA_3809) Thread-Topic: mtd/ftl: Fix memleak in ftl_add_mtd() Thread-Index: V5oJKIljgIpBvfWjk+sGiwgnVw0TaA== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE,T_SPF_PERMERROR 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 ----- Ursprüngliche Mail ----- > Von: "cuigaosheng" > > PING There seems to be a problem with your caps lock key. ;-) > 在 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. Is this leak observable via kmemleak or such? I always thought ->remove_dev() unconditionally do a cleanup later. >> 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);