git: 67239b0a33b2 - stable/13 - hwpmc: don't use deprecated copystr(9)

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Fri, 09 Jun 2023 19:58:06 UTC
The branch stable/13 has been updated by mhorne:

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

commit 67239b0a33b22f0e92b975378b060f82fef5593b
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2023-05-05 21:59:15 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2023-06-09 18:14:58 +0000

    hwpmc: don't use deprecated copystr(9)
    
    It is just wrapper around strlcpy(), but results in more complicated
    code. Clean this up to use strlcpy() or snprintf() as appropriate.
    
    Reviewed by:    jkoshy
    MFC after:      2 weeks
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D39910
    
    (cherry picked from commit 31610e34b7e39d573d927ea98346c88f23cabdab)
---
 sys/dev/hwpmc/hwpmc_amd.c     |  7 +------
 sys/dev/hwpmc/hwpmc_arm64.c   |  9 +++------
 sys/dev/hwpmc/hwpmc_armv7.c   |  9 +++------
 sys/dev/hwpmc/hwpmc_beri.c    |  8 ++------
 sys/dev/hwpmc/hwpmc_core.c    | 16 ++--------------
 sys/dev/hwpmc/hwpmc_mips.c    |  8 ++------
 sys/dev/hwpmc/hwpmc_powerpc.c |  9 +++------
 sys/dev/hwpmc/hwpmc_soft.c    |  7 +------
 sys/dev/hwpmc/hwpmc_tsc.c     |  7 +------
 sys/dev/hwpmc/hwpmc_uncore.c  | 16 ++--------------
 10 files changed, 20 insertions(+), 76 deletions(-)

diff --git a/sys/dev/hwpmc/hwpmc_amd.c b/sys/dev/hwpmc/hwpmc_amd.c
index 2b5356924ae6..05584ee1660d 100644
--- a/sys/dev/hwpmc/hwpmc_amd.c
+++ b/sys/dev/hwpmc/hwpmc_amd.c
@@ -905,8 +905,6 @@ amd_intr(struct trapframe *tf)
 static int
 amd_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
 {
-	int error;
-	size_t copied;
 	const struct amd_descr *pd;
 	struct pmc_hw *phw;
 
@@ -918,10 +916,7 @@ amd_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
 	phw = &amd_pcpu[cpu]->pc_amdpmcs[ri];
 	pd  = &amd_pmcdesc[ri];
 
-	if ((error = copystr(pd->pm_descr.pd_name, pi->pm_name,
-		 PMC_NAME_MAX, &copied)) != 0)
-		return error;
-
+	strlcpy(pi->pm_name, pd->pm_descr.pd_name, sizeof(pi->pm_name));
 	pi->pm_class = pd->pm_descr.pd_class;
 
 	if (phw->phw_state & PMC_PHW_FLAG_IS_ENABLED) {
diff --git a/sys/dev/hwpmc/hwpmc_arm64.c b/sys/dev/hwpmc/hwpmc_arm64.c
index 80d97070b913..a89f26f90dd0 100644
--- a/sys/dev/hwpmc/hwpmc_arm64.c
+++ b/sys/dev/hwpmc/hwpmc_arm64.c
@@ -425,9 +425,7 @@ arm64_intr(struct trapframe *tf)
 static int
 arm64_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
 {
-	char arm64_name[PMC_NAME_MAX];
 	struct pmc_hw *phw;
-	int error;
 
 	KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
 	    ("[arm64,%d], illegal CPU %d", __LINE__, cpu));
@@ -435,11 +433,10 @@ arm64_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
 	    ("[arm64,%d] row-index %d out of range", __LINE__, ri));
 
 	phw = &arm64_pcpu[cpu]->pc_arm64pmcs[ri];
-	snprintf(arm64_name, sizeof(arm64_name), "ARMV8-%d", ri);
-	if ((error = copystr(arm64_name, pi->pm_name, PMC_NAME_MAX,
-	    NULL)) != 0)
-		return (error);
+
+	snprintf(pi->pm_name, sizeof(pi->pm_name), "ARMV8-%d", ri);
 	pi->pm_class = PMC_CLASS_ARMV8;
+
 	if (phw->phw_state & PMC_PHW_FLAG_IS_ENABLED) {
 		pi->pm_enabled = TRUE;
 		*ppmc = phw->phw_pmc;
diff --git a/sys/dev/hwpmc/hwpmc_armv7.c b/sys/dev/hwpmc/hwpmc_armv7.c
index cd4761df46be..2cfac1e857bd 100644
--- a/sys/dev/hwpmc/hwpmc_armv7.c
+++ b/sys/dev/hwpmc/hwpmc_armv7.c
@@ -389,9 +389,7 @@ armv7_intr(struct trapframe *tf)
 static int
 armv7_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
 {
-	char armv7_name[PMC_NAME_MAX];
 	struct pmc_hw *phw;
-	int error;
 
 	KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
 	    ("[armv7,%d], illegal CPU %d", __LINE__, cpu));
@@ -399,11 +397,10 @@ armv7_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
 	    ("[armv7,%d] row-index %d out of range", __LINE__, ri));
 
 	phw = &armv7_pcpu[cpu]->pc_armv7pmcs[ri];
-	snprintf(armv7_name, sizeof(armv7_name), "ARMV7-%d", ri);
-	if ((error = copystr(armv7_name, pi->pm_name, PMC_NAME_MAX,
-	    NULL)) != 0)
-		return error;
+
+	snprintf(pi->pm_name, sizeof(pi->pm_name), "ARMV7-%d", ri);
 	pi->pm_class = PMC_CLASS_ARMV7;
+
 	if (phw->phw_state & PMC_PHW_FLAG_IS_ENABLED) {
 		pi->pm_enabled = TRUE;
 		*ppmc = phw->phw_pmc;
diff --git a/sys/dev/hwpmc/hwpmc_beri.c b/sys/dev/hwpmc/hwpmc_beri.c
index 4fec1b950299..ce15bb57fda4 100644
--- a/sys/dev/hwpmc/hwpmc_beri.c
+++ b/sys/dev/hwpmc/hwpmc_beri.c
@@ -366,8 +366,6 @@ static int
 beri_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
 {
 	struct pmc_hw *phw;
-	char beri_name[PMC_NAME_MAX];
-	int error;
 
 	KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
 	    ("[beri,%d], illegal CPU %d", __LINE__, cpu));
@@ -375,10 +373,8 @@ beri_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
 	    ("[beri,%d] row-index %d out of range", __LINE__, ri));
 
 	phw = &beri_pcpu[cpu]->pc_beripmcs[ri];
-	snprintf(beri_name, sizeof(beri_name), "MIPS-%d", ri);
-	if ((error = copystr(beri_name, pi->pm_name, PMC_NAME_MAX,
-	    NULL)) != 0)
-		return error;
+
+	snprintf(pi->pm_name, sizeof(pi->pm_name), "MIPS-%d", ri);
 	pi->pm_class = beri_pmc_spec.ps_cpuclass;
 	if (phw->phw_state & PMC_PHW_FLAG_IS_ENABLED) {
 		pi->pm_enabled = TRUE;
diff --git a/sys/dev/hwpmc/hwpmc_core.c b/sys/dev/hwpmc/hwpmc_core.c
index 5d29931c90f0..ad9d323bdb9a 100644
--- a/sys/dev/hwpmc/hwpmc_core.c
+++ b/sys/dev/hwpmc/hwpmc_core.c
@@ -330,17 +330,11 @@ iaf_config_pmc(int cpu, int ri, struct pmc *pm)
 static int
 iaf_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
 {
-	int error;
 	struct pmc_hw *phw;
-	char iaf_name[PMC_NAME_MAX];
 
 	phw = &core_pcpu[cpu]->pc_corepmcs[ri + core_iaf_ri];
 
-	(void) snprintf(iaf_name, sizeof(iaf_name), "IAF-%d", ri);
-	if ((error = copystr(iaf_name, pi->pm_name, PMC_NAME_MAX,
-	    NULL)) != 0)
-		return (error);
-
+	snprintf(pi->pm_name, sizeof(pi->pm_name), "IAF-%d", ri);
 	pi->pm_class = PMC_CLASS_IAF;
 
 	if (phw->phw_state & PMC_PHW_FLAG_IS_ENABLED) {
@@ -814,17 +808,11 @@ iap_config_pmc(int cpu, int ri, struct pmc *pm)
 static int
 iap_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
 {
-	int error;
 	struct pmc_hw *phw;
-	char iap_name[PMC_NAME_MAX];
 
 	phw = &core_pcpu[cpu]->pc_corepmcs[ri];
 
-	(void) snprintf(iap_name, sizeof(iap_name), "IAP-%d", ri);
-	if ((error = copystr(iap_name, pi->pm_name, PMC_NAME_MAX,
-	    NULL)) != 0)
-		return (error);
-
+	snprintf(pi->pm_name, sizeof(pi->pm_name), "IAP-%d", ri);
 	pi->pm_class = PMC_CLASS_IAP;
 
 	if (phw->phw_state & PMC_PHW_FLAG_IS_ENABLED) {
diff --git a/sys/dev/hwpmc/hwpmc_mips.c b/sys/dev/hwpmc/hwpmc_mips.c
index edf83154dc57..1ed3fdea8915 100644
--- a/sys/dev/hwpmc/hwpmc_mips.c
+++ b/sys/dev/hwpmc/hwpmc_mips.c
@@ -319,9 +319,7 @@ mips_pmc_intr(struct trapframe *tf)
 static int
 mips_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
 {
-	int error;
 	struct pmc_hw *phw;
-	char mips_name[PMC_NAME_MAX];
 
 	KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
 	    ("[mips,%d], illegal CPU %d", __LINE__, cpu));
@@ -329,10 +327,8 @@ mips_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
 	    ("[mips,%d] row-index %d out of range", __LINE__, ri));
 
 	phw = &mips_pcpu[cpu]->pc_mipspmcs[ri];
-	snprintf(mips_name, sizeof(mips_name), "MIPS-%d", ri);
-	if ((error = copystr(mips_name, pi->pm_name, PMC_NAME_MAX,
-	    NULL)) != 0)
-		return error;
+
+	snprintf(pi->pm_name, sizeof(pi->pm_name), "MIPS-%d", ri);
 	pi->pm_class = mips_pmc_spec.ps_cpuclass;
 	if (phw->phw_state & PMC_PHW_FLAG_IS_ENABLED) {
 		pi->pm_enabled = TRUE;
diff --git a/sys/dev/hwpmc/hwpmc_powerpc.c b/sys/dev/hwpmc/hwpmc_powerpc.c
index 7c6df5825399..4c2a9cf84ef4 100644
--- a/sys/dev/hwpmc/hwpmc_powerpc.c
+++ b/sys/dev/hwpmc/hwpmc_powerpc.c
@@ -122,19 +122,16 @@ powerpc_switch_out(struct pmc_cpu *pc, struct pmc_process *pp)
 int
 powerpc_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
 {
-	int error;
 	struct pmc_hw *phw;
-	char powerpc_name[PMC_NAME_MAX];
 
 	KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
 	    ("[powerpc,%d], illegal CPU %d", __LINE__, cpu));
 
 	phw = &powerpc_pcpu[cpu]->pc_ppcpmcs[ri];
-	snprintf(powerpc_name, sizeof(powerpc_name), "POWERPC-%d", ri);
-	if ((error = copystr(powerpc_name, pi->pm_name, PMC_NAME_MAX,
-	    NULL)) != 0)
-		return error;
+
+	snprintf(pi->pm_name, sizeof(pi->pm_name), "POWERPC-%d", ri);
 	pi->pm_class = powerpc_pcpu[cpu]->pc_class;
+
 	if (phw->phw_state & PMC_PHW_FLAG_IS_ENABLED) {
 		pi->pm_enabled = TRUE;
 		*ppmc          = phw->phw_pmc;
diff --git a/sys/dev/hwpmc/hwpmc_soft.c b/sys/dev/hwpmc/hwpmc_soft.c
index cf2401e9159e..f3a6ffc70677 100644
--- a/sys/dev/hwpmc/hwpmc_soft.c
+++ b/sys/dev/hwpmc/hwpmc_soft.c
@@ -159,8 +159,6 @@ soft_config_pmc(int cpu, int ri, struct pmc *pm)
 static int
 soft_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
 {
-	int error;
-	size_t copied;
 	const struct soft_descr *pd;
 	struct pmc_hw *phw;
 
@@ -172,10 +170,7 @@ soft_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
 	phw = &soft_pcpu[cpu]->soft_hw[ri];
 	pd  = &soft_pmcdesc[ri];
 
-	if ((error = copystr(pd->pm_descr.pd_name, pi->pm_name,
-	    PMC_NAME_MAX, &copied)) != 0)
-		return (error);
-
+	strlcpy(pi->pm_name, pd->pm_descr.pd_name, sizeof(pi->pm_name));
 	pi->pm_class = pd->pm_descr.pd_class;
 
 	if (phw->phw_state & PMC_PHW_FLAG_IS_ENABLED) {
diff --git a/sys/dev/hwpmc/hwpmc_tsc.c b/sys/dev/hwpmc/hwpmc_tsc.c
index d59c8908f4ca..25b2e9f8fd57 100644
--- a/sys/dev/hwpmc/hwpmc_tsc.c
+++ b/sys/dev/hwpmc/hwpmc_tsc.c
@@ -115,8 +115,6 @@ tsc_config_pmc(int cpu, int ri, struct pmc *pm)
 static int
 tsc_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
 {
-	int error;
-	size_t copied;
 	const struct tsc_descr *pd;
 	struct pmc_hw *phw;
 
@@ -127,10 +125,7 @@ tsc_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
 	phw = &tsc_pcpu[cpu]->tc_hw;
 	pd  = &tsc_pmcdesc[ri];
 
-	if ((error = copystr(pd->pm_descr.pd_name, pi->pm_name,
-	    PMC_NAME_MAX, &copied)) != 0)
-		return (error);
-
+	strlcpy(pi->pm_name, pd->pm_descr.pd_name, sizeof(pi->pm_name));
 	pi->pm_class = pd->pm_descr.pd_class;
 
 	if (phw->phw_state & PMC_PHW_FLAG_IS_ENABLED) {
diff --git a/sys/dev/hwpmc/hwpmc_uncore.c b/sys/dev/hwpmc/hwpmc_uncore.c
index c9ae128b55cf..47d1e62e2698 100644
--- a/sys/dev/hwpmc/hwpmc_uncore.c
+++ b/sys/dev/hwpmc/hwpmc_uncore.c
@@ -237,17 +237,11 @@ ucf_config_pmc(int cpu, int ri, struct pmc *pm)
 static int
 ucf_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
 {
-	int error;
 	struct pmc_hw *phw;
-	char ucf_name[PMC_NAME_MAX];
 
 	phw = &uncore_pcpu[cpu]->pc_uncorepmcs[ri + uncore_ucf_ri];
 
-	(void) snprintf(ucf_name, sizeof(ucf_name), "UCF-%d", ri);
-	if ((error = copystr(ucf_name, pi->pm_name, PMC_NAME_MAX,
-	    NULL)) != 0)
-		return (error);
-
+	snprintf(pi->pm_name, sizeof(pi->pm_name), "UCF-%d", ri);
 	pi->pm_class = PMC_CLASS_UCF;
 
 	if (phw->phw_state & PMC_PHW_FLAG_IS_ENABLED) {
@@ -564,17 +558,11 @@ ucp_config_pmc(int cpu, int ri, struct pmc *pm)
 static int
 ucp_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
 {
-	int error;
 	struct pmc_hw *phw;
-	char ucp_name[PMC_NAME_MAX];
 
 	phw = &uncore_pcpu[cpu]->pc_uncorepmcs[ri];
 
-	(void) snprintf(ucp_name, sizeof(ucp_name), "UCP-%d", ri);
-	if ((error = copystr(ucp_name, pi->pm_name, PMC_NAME_MAX,
-	    NULL)) != 0)
-		return (error);
-
+	snprintf(pi->pm_name, sizeof(pi->pm_name), "UCP-%d", ri);
 	pi->pm_class = PMC_CLASS_UCP;
 
 	if (phw->phw_state & PMC_PHW_FLAG_IS_ENABLED) {