Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp193774imw; Fri, 15 Jul 2022 00:50:47 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vJXYYGbVHopq3yN87cuhgYPp9e/1WTAWCLYAfyqDR/uvIw57Hk2aVsowJOpPqX8OMkglAC X-Received: by 2002:a05:6402:35cc:b0:43a:75e1:935f with SMTP id z12-20020a05640235cc00b0043a75e1935fmr17094345edc.369.1657871446801; Fri, 15 Jul 2022 00:50:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657871446; cv=none; d=google.com; s=arc-20160816; b=dTbLXUyKIvcYiQLJDfDvecf58KgcR6tpYQC/cmsFjID1PwUV43WcaBxbvY2i59/ceN kkUMLjh0fFGYgskkqdqizEMI7O00AVMDASlwVLdeMQeo3mwzbNCoR+kRN7HxieiPzf4L xMPciCy7G1OILdq6Z7/cEcj1Wgrd+RIqaRlDNL167NkMxRa9oVhbIusqIx2NT5ADZOsn 9P2Qyo9cAjZn02XJ3zKXk//kPSjis8udjumegkhWz/4ZD2XQSO2EbvXLnPdS4W4HRzhX 5D4COZx7YqWFeoM8uMtBEks3W9kB9bnvO8yCQXGNyadp04AYNntpyblH6atoDZ9L7Dy/ +6hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=7tyaLP5faluF7tVGm0PRaUoQaCEz9KJ+ZZW6zDsBQ1w=; b=irgQhbrjzzACTqPkq80tQggwyVL/AFNvWWWrMYYckFKIRMUlAo30wbmPcZ8MEC5uer NYOtHey4mRQ5ap78vu43s1V4my8A6VVohJivjPMzxlF9f/UiGcTyT6yDoTFlnpA81eVW AkYAPxsotrkheyPE4Tl/jZOLwvL6Izzc6ZKtHQoThaYoL+y2+hZzz+l37iXYdi3TPErW nKkDgGuNEY7hZ/nbiMFQH0TyAYIVT33B5boG3FVBJOWSqhb3YsW/UVSrzPIofnywJVes Pi9PxsaEeQmz70gicGTwfAADdWT4FiDueqsx5ckaoS7MIm0a0Gf8H5RhM5kMi5UUH5mO ciOQ== 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 nb36-20020a1709071ca400b0072ee5600d78si3686936ejc.933.2022.07.15.00.50.22; Fri, 15 Jul 2022 00:50:46 -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 S231236AbiGOHLM (ORCPT + 99 others); Fri, 15 Jul 2022 03:11:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230383AbiGOHLJ (ORCPT ); Fri, 15 Jul 2022 03:11:09 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDFF4213 for ; Fri, 15 Jul 2022 00:11:08 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4LkjDK08K1zFpxR; Fri, 15 Jul 2022 15:10:08 +0800 (CST) Received: from dggphis33418.huawei.com (10.244.148.83) 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; Fri, 15 Jul 2022 15:11:06 +0800 From: Gaosheng Cui To: , , , CC: , , , Subject: [PATCH -next] mtd/ftl: Fix memleak in ftl_add_mtd() Date: Fri, 15 Jul 2022 15:11:05 +0800 Message-ID: <20220715071105.2321311-1-cuigaosheng1@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.244.148.83] 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,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 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); -- 2.25.1