From patchwork Thu Oct 10 12:53:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13830066 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36B9FCF11E9 for ; Thu, 10 Oct 2024 12:54:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC0466B0082; Thu, 10 Oct 2024 08:54:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B70136B0083; Thu, 10 Oct 2024 08:54:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5E976B0085; Thu, 10 Oct 2024 08:54:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 884866B0082 for ; Thu, 10 Oct 2024 08:54:17 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7EF92C01A0 for ; Thu, 10 Oct 2024 12:54:13 +0000 (UTC) X-FDA: 82657685754.18.668AA2C Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf20.hostedemail.com (Postfix) with ESMTP id EA9971C0012 for ; Thu, 10 Oct 2024 12:54:13 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of ruanjinjie@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=ruanjinjie@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728564718; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=Y5rrQphXKiHR6OIC5k0E4mTF+N79xg1Z6fCf9jQ5T6s=; b=csyU8InirHZwodVvvZBymw4bP7qIKtyMv5T6oNB7NONFGN7BvN44wCVLnoXbmekA4qDpl8 ezfMQyUBuDxiTLQHzdzn6cCwLJj3mTIEDP8mX5Fx6cQJ8vD5bPVB0kxsi8erqs66AitmWE 56lw9VBi3VVl+/ZOsLyNpJ3lTqB2tKg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728564718; a=rsa-sha256; cv=none; b=DsXZIqxZrqoqafG1D6c0fijcI/l9u+b0mU4Aq9NiODRv304p+hVaoW4JXf5anCjacEDUvQ YLTNJUht+rtn2XEqR6Utpmkx1nERcyheT5taII1d7xgV1K7K7N09cpWBsff79o80ldUS33 pNbpKNI3jYwnM9Unfxz8BfSsAMuBmNo= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of ruanjinjie@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=ruanjinjie@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4XPV300dX8z1HKkn; Thu, 10 Oct 2024 20:50:04 +0800 (CST) Received: from kwepemh500013.china.huawei.com (unknown [7.202.181.146]) by mail.maildlp.com (Postfix) with ESMTPS id 017A41400DC; Thu, 10 Oct 2024 20:54:11 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemh500013.china.huawei.com (7.202.181.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 10 Oct 2024 20:54:10 +0800 From: Jinjie Ruan To: , , , , CC: Subject: [PATCH] mm/damon: Fix memory leak in damon_sysfs_test_add_targets() Date: Thu, 10 Oct 2024 20:53:23 +0800 Message-ID: <20241010125323.3127187-1-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemh500013.china.huawei.com (7.202.181.146) X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: EA9971C0012 X-Stat-Signature: 9k18c6tjudh151c85mndzjcx3iqgabpk X-HE-Tag: 1728564853-157779 X-HE-Meta: U2FsdGVkX19sVDnND0TVZqXCPKImDl/HUT1RfyU6p+a+fc7UxDsOGZpbKACYicbygXlyxO9p1sX6SsqnNDojtiYnhAxK/Wo70bwA4uZ56BqZ01GV6EQgk/lCGFZHnGsZmVtyQEaEVqDh4rSnFCebCoDFWJLpB7sAwpPcsoWszJa5a3ptjveN3ZxM2fNl3WmDofucDALKvfTHywpEslGLKpSVv8Jvl8TI+DtVkfmTacmZxitht686N8+xaUKlK3wWxhjVBJCcw9aBq3AxQN/e/ynJ76vWguycq1I3PX8oN4svAXf08vJZGsgQfJdm8ArRGfnb1cdDoobXTe/HoqNezLjdlOA4p21HduUtygQC2jZ2gjLyz4B7vzNBcCoB7XKBPpbaaEtTrNdELMe9B+AuRvmskNDoz3j8jZ6uEBSGxP3qzmQ//hbo6fSYWcjM3jV5QDAU7iO8OGojMyT9TKgQKK9BSJBZYFPQHJoHbHP5LkncCcFJoqoHEQjU8W8cfHmx5WZ5ZGG7tZnXu3w59Ljvl3Xme1dkhaTiuUE9PLSZDh/V4655LAxDO53rEtwkhcFscYpxIVb2HyMVDemaUCk0Xh6LQUsHspwE5+vr62gzIlTG+NpNtca70EHNxIaZJwNW2JFGG/0Am6ByOybLJmbZrUXkmN7ONVOASp5kLVVrLb1uqNzQ2R8XKm620J+i1mDED/wILSQFL1GLWaXBpeGMA9xQnUXhc2JKFhwyLi5RQeNDZv+ohDmPBW4NBCLdriCIqm5Y5m/CpXUGKSRee4efHR9dIx43DdBX2+1C3mGsXfwICNtiFVxC418w2yFWvMwqInnd/DTtwfatNKgwSKNwNq22hrjG3e09GYi022pdsGiuNmdy79UXFoQeSTeT2DUpzpmtVoPuCCZ/SsahtuOCVJy98TBihlD2WYVYJn544xW/DZoY2PvrMpgX8yrRMwI1BcuK7m4O9HP1BXQt4RL ym7lhfZw E0wIUuSsVXXgG4NAJ7g/EmwWym3l/X09uf21O51rkXWIDgLYrt7wiU7+4KOw7zMg2yoKyYsuMilpj4iKNdIG8MX7g1lgKhma92uFYJ9fYnlCHHOGuolUQ33dm2MVnrhwDbQUZtyQkd5m7/av1tt+hWzjzV47NtPdZxNSjr736YCM5WmXf93UpBrSZjXQ/rlxVcR8jFjvbufiR2yK2P82sG1CA5g== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The sysfs_target->regions allocated in damon_sysfs_regions_alloc() is not freed in damon_sysfs_test_add_targets(), which cause the following memory leak, free it to fix it. unreferenced object 0xffffff80c2a8db80 (size 96): comm "kunit_try_catch", pid 187, jiffies 4294894363 hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace (crc 0): [<0000000001e3714d>] kmemleak_alloc+0x34/0x40 [<000000008e6835c1>] __kmalloc_cache_noprof+0x26c/0x2f4 [<000000001286d9f8>] damon_sysfs_test_add_targets+0x1cc/0x738 [<0000000032ef8f77>] kunit_try_run_case+0x13c/0x3ac [<00000000f3edea23>] kunit_generic_run_threadfn_adapter+0x80/0xec [<00000000adf936cf>] kthread+0x2e8/0x374 [<0000000041bb1628>] ret_from_fork+0x10/0x20 Cc: stable@vger.kernel.org Fixes: b8ee5575f763 ("mm/damon/sysfs-test: add a unit test for damon_sysfs_set_targets()") Signed-off-by: Jinjie Ruan Reviewed-by: SeongJae Park --- mm/damon/tests/sysfs-kunit.h | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/damon/tests/sysfs-kunit.h b/mm/damon/tests/sysfs-kunit.h index 1c9b596057a7..7b5c7b307da9 100644 --- a/mm/damon/tests/sysfs-kunit.h +++ b/mm/damon/tests/sysfs-kunit.h @@ -67,6 +67,7 @@ static void damon_sysfs_test_add_targets(struct kunit *test) damon_destroy_ctx(ctx); kfree(sysfs_targets->targets_arr); kfree(sysfs_targets); + kfree(sysfs_target->regions); kfree(sysfs_target); }