hwpmc_arm64: plug memory leak

Free allocated per-CPU structures in the pcpu_fini and finalize methods.

While here, add debug trace entries to these methods.

Reviewed by:	jkoshy, andrew
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41268
This commit is contained in:
Mitchell Horne 2023-08-03 11:09:48 -03:00
parent 32e47f6272
commit 8bdceaecab

View file

@ -450,7 +450,7 @@ arm64_pcpu_init(struct pmc_mdep *md, int cpu)
KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
("[arm64,%d] wrong cpu number %d", __LINE__, cpu));
PMCDBG1(MDP, INI, 1, "arm64-init cpu=%d", cpu);
PMCDBG0(MDP, INI, 1, "arm64-pcpu-init");
arm64_pcpu[cpu] = pac = malloc(sizeof(struct arm64_cpu), M_PMC,
M_WAITOK | M_ZERO);
@ -491,10 +491,16 @@ arm64_pcpu_fini(struct pmc_mdep *md, int cpu)
{
uint32_t pmcr;
PMCDBG0(MDP, INI, 1, "arm64-pcpu-fini");
pmcr = arm64_pmcr_read();
pmcr &= ~PMCR_E;
arm64_pmcr_write(pmcr);
free(arm64_pcpu[cpu]->pc_arm64pmcs, M_PMC);
free(arm64_pcpu[cpu], M_PMC);
arm64_pcpu[cpu] = NULL;
return (0);
}
@ -605,5 +611,7 @@ pmc_arm64_initialize(void)
void
pmc_arm64_finalize(struct pmc_mdep *md)
{
PMCDBG0(MDP, INI, 1, "arm64-finalize");
free(arm64_pcpu, M_PMC);
}