git: fad7a311d9ff - stable/13 - hwpmc: Make powerpc memory allocation alike to x86.

From: Alexander Motin <mav_at_FreeBSD.org>
Date: Mon, 04 Jul 2022 18:09:26 UTC
The branch stable/13 has been updated by mav:

URL: https://cgit.FreeBSD.org/src/commit/?id=fad7a311d9ffa394470e427e6d928269640f602b

commit fad7a311d9ffa394470e427e6d928269640f602b
Author:     Alexander Motin <mav@FreeBSD.org>
AuthorDate: 2022-06-01 18:50:27 +0000
Commit:     Alexander Motin <mav@FreeBSD.org>
CommitDate: 2022-07-04 17:48:10 +0000

    hwpmc: Make powerpc memory allocation alike to x86.
    
    It should remove some unneeded pointer dereferences.
    
    MFC after:      1 month
    
    (cherry picked from commit 47699fc265b9d966b4eba6bc0c41739ac793f52b)
---
 sys/dev/hwpmc/hwpmc_powerpc.c | 8 +++-----
 sys/dev/hwpmc/hwpmc_powerpc.h | 4 ++--
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/sys/dev/hwpmc/hwpmc_powerpc.c b/sys/dev/hwpmc/hwpmc_powerpc.c
index e97211f0d9a6..537e263d4c15 100644
--- a/sys/dev/hwpmc/hwpmc_powerpc.c
+++ b/sys/dev/hwpmc/hwpmc_powerpc.c
@@ -166,10 +166,8 @@ powerpc_pcpu_init(struct pmc_mdep *md, int cpu)
 	    ("[powerpc,%d] wrong cpu number %d", __LINE__, cpu));
 	PMCDBG1(MDP,INI,1,"powerpc-init cpu=%d", cpu);
 
-	powerpc_pcpu[cpu] = pac = malloc(sizeof(struct powerpc_cpu), M_PMC,
-	    M_WAITOK|M_ZERO);
-	pac->pc_ppcpmcs = malloc(sizeof(struct pmc_hw) * ppc_max_pmcs,
-	    M_PMC, M_WAITOK|M_ZERO);
+	powerpc_pcpu[cpu] = pac = malloc(sizeof(struct powerpc_cpu) +
+	    ppc_max_pmcs * sizeof(struct pmc_hw), M_PMC, M_WAITOK | M_ZERO);
 	pac->pc_class =
 	    md->pmd_classdep[PMC_MDEP_CLASS_INDEX_POWERPC].pcd_class;
 
@@ -192,8 +190,8 @@ powerpc_pcpu_fini(struct pmc_mdep *md, int cpu)
 {
 	PMCDBG1(MDP,INI,1,"powerpc-fini cpu=%d", cpu);
 
-	free(powerpc_pcpu[cpu]->pc_ppcpmcs, M_PMC);
 	free(powerpc_pcpu[cpu], M_PMC);
+	powerpc_pcpu[cpu] = NULL;
 
 	return (0);
 }
diff --git a/sys/dev/hwpmc/hwpmc_powerpc.h b/sys/dev/hwpmc/hwpmc_powerpc.h
index 31c20592a21f..551f59b60528 100644
--- a/sys/dev/hwpmc/hwpmc_powerpc.h
+++ b/sys/dev/hwpmc/hwpmc_powerpc.h
@@ -58,8 +58,8 @@
 #define	PPC_OVERFLOWCNT_MAX	0x200000000UL
 
 struct powerpc_cpu {
-	struct pmc_hw   *pc_ppcpmcs;
-	enum pmc_class	 pc_class;
+	enum pmc_class	pc_class;
+	struct pmc_hw	pc_ppcpmcs[];
 };
 
 struct pmc_ppc_event {