Received: by 2002:a05:7412:f584:b0:e2:908c:2ebd with SMTP id eh4csp2064061rdb; Tue, 5 Sep 2023 13:15:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGgi2UKyyudkBjMmj/ln1M69HUjPa85LZGCPbI7Y7rCGaqAs5WbmG9ZL8eNF0mmQoxpkxCG X-Received: by 2002:a17:902:ec86:b0:1c0:d17a:bfe9 with SMTP id x6-20020a170902ec8600b001c0d17abfe9mr12364495plg.46.1693944936628; Tue, 05 Sep 2023 13:15:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693944936; cv=none; d=google.com; s=arc-20160816; b=UWbd1NtjItfGCxcme9VD6Fx+/dPfsYrRI5P7/oGOVuEUVa5SI9PLM/TIw4+gLJVbt9 Gh3CcNhMmBHFyJ0XfXPuihXV2TZn/EeemqZiVbvB8u41MpzH8uZxidqyBB22o1OGQdZr 1rIkGYeJJIT/TG2yhMGvJp10mZjYpwOxLOztgm51YyaUtV+ADlc89CkDsF8IfVEcbgfb Gfw1AD2rKhfclnGkPEV776cpARGj0gp8Y7+2CuEuilwqJQPefAaXqzFQUwJJhLU7z6uY bNdRBSsPSgWpSZ4jtmMR52mdU+h6HYdluTv2wqe2FhFFzVcgjGFg+/jg3xG9EXJ5kfku xSSg== 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=JJ0q0qPTjjM63UE1usBGrmcOWom66ZP0NNMxFVNtkuM=; fh=grMkqw93Nq5+S1WBJ1xSm+S4FROrsAAG1NaT8oJm5Dw=; b=mxpT+1ulAAdBVdueAkrbIVLvOVtvONBZvRXojOtQvr3ZDCMdzVY3019RedSQrUuG0B w64YxDEVuoUwjLcZsZOw1L/gi5hZMPkIjVFCYJnMITbl4+dJ6HaAH6pg3HUTG8kwhJvN 2g4F4zfbGpmPzjZbW5ZIxoTdY0AZ8+X+ufJNEE9Ulge6wx9rIkWP3DBlaCYEYqYIXHDi 01uJosyrlP+Ujtgf0adGAVqntdO4aWbTl4K+yJXtnFHxBc/RdL9VvOeuF1q4PuD5hNBQ l24NLXk+G9med1T+2cI9GX22qBDs63zqqwubSe/xjfd+NbAw6tKduRy/BJKwL5lxhlpX 4+3w== 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 t7-20020a1709027fc700b001b8922e82e3si9919220plb.297.2023.09.05.13.15.22; Tue, 05 Sep 2023 13:15:36 -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 S1350519AbjIERE7 (ORCPT + 99 others); Tue, 5 Sep 2023 13:04:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354023AbjIEJPR (ORCPT ); Tue, 5 Sep 2023 05:15:17 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4CB4C4 for ; Tue, 5 Sep 2023 02:15:13 -0700 (PDT) Received: from lhrpeml500004.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Rg0Dc2kG6z6D8WV; Tue, 5 Sep 2023 17:13:52 +0800 (CST) Received: from mscphis00759.huawei.com (10.123.66.134) by lhrpeml500004.china.huawei.com (7.191.163.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Tue, 5 Sep 2023 10:15:11 +0100 From: Konstantin Meskhidze To: CC: , , , , , , , , , Subject: [PATCH] drivers: nvdimm: fix possible memory leak Date: Tue, 5 Sep 2023 17:15:07 +0800 Message-ID: <20230905091507.1672987-1-konstantin.meskhidze@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.123.66.134] X-ClientProxiedBy: mscpeml100001.china.huawei.com (7.188.26.227) To lhrpeml500004.china.huawei.com (7.191.163.9) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS 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 Memory pointed by 'nd_pmu->pmu.attr_groups[NVDIMM_PMU_CPUMASK_ATTR]->attrs[0]' is allocated in function 'nvdimm_pmu_cpu_hotplug_init' via 'create_cpumask_attr_group' call. But not released in function 'nvdimm_pmu_free_hotplug_memory' or anywhere else before memory pointed by 'nd_pmu->pmu.attr_groups[NVDIMM_PMU_CPUMASK_ATTR]->attrs' will be freed. Fixes: 0fab1ba6ad6b ("drivers/nvdimm: Add perf interface to expose nvdimm performance stats") Co-developed-by: Ivanov Mikhail Signed-off-by: Konstantin Meskhidze --- drivers/nvdimm/nd_perf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/nvdimm/nd_perf.c b/drivers/nvdimm/nd_perf.c index 2b6dc80d8..ecfa1f635 100644 --- a/drivers/nvdimm/nd_perf.c +++ b/drivers/nvdimm/nd_perf.c @@ -264,10 +264,14 @@ static void nvdimm_pmu_free_hotplug_memory(struct nvdimm_pmu *nd_pmu) { cpuhp_state_remove_instance_nocalls(nd_pmu->cpuhp_state, &nd_pmu->node); cpuhp_remove_multi_state(nd_pmu->cpuhp_state); - if (nd_pmu->pmu.attr_groups[NVDIMM_PMU_CPUMASK_ATTR]) + if (nd_pmu->pmu.attr_groups[NVDIMM_PMU_CPUMASK_ATTR]) { + if (nd_pmu->pmu.attr_groups[NVDIMM_PMU_CPUMASK_ATTR]->attrs) + kfree(nd_pmu->pmu.attr_groups[NVDIMM_PMU_CPUMASK_ATTR]->attrs[0]); + kfree(nd_pmu->pmu.attr_groups[NVDIMM_PMU_CPUMASK_ATTR]->attrs); + } kfree(nd_pmu->pmu.attr_groups[NVDIMM_PMU_CPUMASK_ATTR]); } int register_nvdimm_pmu(struct nvdimm_pmu *nd_pmu, struct platform_device *pdev) -- 2.34.1