Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4995928ybl; Tue, 14 Jan 2020 01:36:07 -0800 (PST) X-Google-Smtp-Source: APXvYqzt9DHM/xRryzM/sYNiii/wKmtAB3HDdFdjWzMWYK1uMdSmgYo4LKLWV6xNDOAh+VIJTvyR X-Received: by 2002:aca:de06:: with SMTP id v6mr15568056oig.168.1578994567052; Tue, 14 Jan 2020 01:36:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578994567; cv=none; d=google.com; s=arc-20160816; b=Rq8TcOMUk4S++QaLwyEtgKa0IJ96MCHIXusW4rlpgIboYTPPQMNh3KXyWOLIyTzvgF sAcvtISFqbocCqqy7dx4/tJRejIoxiIxDvXZMquwoTvCuzWCeuFnZR6t3FqhXMoOtcjq m+XjFy+ZFPfRcvVmNYK20ZKN8lSIjCdoDBu7ywVuqhf/byJha0cxqY5qaUULsg3xpxDY LwcxIXyx6t5BMeLfWGF6ml2cakCWcxa9Sfu9bXtNwlqNIuN5qP/Pzy910s7JcuBsN1WU j9UNW9Kqt4zy3Ekg4CBQjoAEgPqi7CrOMOusB/LpX+SiQRaUitgFRr+bpJtvOZPClBPu 6ipw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=FJvfSXYwdoIuwVHlzIXOkWQisEsxqQEfaNKKl7axelo=; b=yR0/LRVFPBg5Qw5/c23+YcDEQWLLI0Siwo0sMH7hK/BkvSv4hFxWzaSsm3WhH6qcVA KR4iFXllG7aHRvHtEX784xWXbWiOpR5KVZqlwPA6O4ZIBdpUujjFts6d4TvoUGmLPOzq LBPji5caFXn4CnxhkLVuP8rJqQnQU88GII2OkXiPb1j/TD2dqEvdAbcUTmXhgOcD6l98 h7/v6v1YAmfc75zKzwbTTLUZabgDfVl8b94hdZCMD8C6WCXVXYJnXgqjQUzXWeoSEWhf bVTz0bostRKogehX+A8Xb3mFJbxsSDMT2wwfaYwL4FLlKj1NpIztk8eccmOG97NcwnP9 AaVg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w11si7139579oic.62.2020.01.14.01.35.56; Tue, 14 Jan 2020 01:36:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728899AbgANJfH (ORCPT + 99 others); Tue, 14 Jan 2020 04:35:07 -0500 Received: from mail5.windriver.com ([192.103.53.11]:54044 "EHLO mail5.wrs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725956AbgANJfH (ORCPT ); Tue, 14 Jan 2020 04:35:07 -0500 Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail5.wrs.com (8.15.2/8.15.2) with ESMTPS id 00E9XCOp024222 (version=TLSv1 cipher=AES256-SHA bits=256 verify=FAIL); Tue, 14 Jan 2020 01:33:33 -0800 Received: from pek-qwang2-d1.wrs.com (128.224.162.199) by ALA-HCA.corp.ad.wrs.com (147.11.189.40) with Microsoft SMTP Server id 14.3.468.0; Tue, 14 Jan 2020 01:33:07 -0800 From: To: , , CC: , , Subject: [PATCH] ubi: fix memory leak from ubi->fm_anchor Date: Tue, 14 Jan 2020 17:33:05 +0800 Message-ID: <20200114093305.666-1-quanyang.wang@windriver.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Quanyang Wang Some ubi_wl_entry are allocated in erase_aeb() and one of them is assigned to ubi->fm_anchor in __erase_worker(). And it should be freed like others which are freed in tree_destroy(). Otherwise, it will cause a memory leak: unreferenced object 0xbc094318 (size 24): comm "ubiattach", pid 491, jiffies 4294954015 (age 420.110s) hex dump (first 24 bytes): 30 43 09 bc 00 00 00 00 00 00 00 00 01 00 00 00 0C.............. 02 00 00 00 04 00 00 00 ........ backtrace: [<6c2d5089>] erase_aeb+0x28/0xc8 [] ubi_wl_init+0x1d8/0x4a8 [] ubi_attach+0xffc/0x10d0 [] ubi_attach_mtd_dev+0x5b4/0x9fc [] ctrl_cdev_ioctl+0xb8/0x1d8 [<72b250f2>] vfs_ioctl+0x28/0x3c [] do_vfs_ioctl+0xb0/0x798 [] ksys_ioctl+0x58/0x74 [<5355bdbe>] ret_fast_syscall+0x0/0x54 [<90c6c3ca>] 0x7eadf854 Signed-off-by: Quanyang Wang --- drivers/mtd/ubi/wl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c index 5d77a38dba54..a5e9d1e4dc34 100644 --- a/drivers/mtd/ubi/wl.c +++ b/drivers/mtd/ubi/wl.c @@ -1885,6 +1885,7 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai) tree_destroy(ubi, &ubi->used); tree_destroy(ubi, &ubi->free); tree_destroy(ubi, &ubi->scrub); + wl_entry_destroy(ubi, ubi->fm_anchor); kfree(ubi->lookuptbl); return err; } @@ -1920,6 +1921,7 @@ void ubi_wl_close(struct ubi_device *ubi) tree_destroy(ubi, &ubi->erroneous); tree_destroy(ubi, &ubi->free); tree_destroy(ubi, &ubi->scrub); + wl_entry_destroy(ubi, ubi->fm_anchor); kfree(ubi->lookuptbl); } -- 2.17.1