diff mbox series

drivers: nvdimm: fix possible memory leak

Message ID 20230905091507.1672987-1-konstantin.meskhidze@huawei.com (mailing list archive)
State Changes Requested
Headers show
Series drivers: nvdimm: fix possible memory leak | expand

Commit Message

Konstantin Meskhidze (A) Sept. 5, 2023, 9:15 a.m. UTC
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 <ivanov.mikhail1@huawei-partners.com>
Signed-off-by: Konstantin Meskhidze <konstantin.meskhidze@huawei.com>
---
 drivers/nvdimm/nd_perf.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Dave Jiang Sept. 8, 2023, 4:36 p.m. UTC | #1
On 9/5/23 02:15, Konstantin Meskhidze wrote:
> 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 <ivanov.mikhail1@huawei-partners.com>
> Signed-off-by: Konstantin Meskhidze <konstantin.meskhidze@huawei.com>

Please change subject to something like below. It needs to be a bit more 
descriptive. Thank you!

nvdimm: Fix possible memory leak in nd_perf hotplug release


> ---
>   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)
diff mbox series

Patch

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)