Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/hwpmc/hwpmc_amd.c
| Show First 20 Lines • Show All 899 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /* | /* | ||||
| * describe a PMC | * describe a PMC | ||||
| */ | */ | ||||
| static int | static int | ||||
| amd_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc) | amd_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc) | ||||
| { | { | ||||
| int error; | |||||
| size_t copied; | |||||
| const struct amd_descr *pd; | const struct amd_descr *pd; | ||||
| struct pmc_hw *phw; | struct pmc_hw *phw; | ||||
| KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), | KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), | ||||
| ("[amd,%d] illegal CPU %d", __LINE__, cpu)); | ("[amd,%d] illegal CPU %d", __LINE__, cpu)); | ||||
| KASSERT(ri >= 0 && ri < AMD_NPMCS, | KASSERT(ri >= 0 && ri < AMD_NPMCS, | ||||
| ("[amd,%d] row-index %d out of range", __LINE__, ri)); | ("[amd,%d] row-index %d out of range", __LINE__, ri)); | ||||
| phw = &amd_pcpu[cpu]->pc_amdpmcs[ri]; | phw = &amd_pcpu[cpu]->pc_amdpmcs[ri]; | ||||
| pd = &amd_pmcdesc[ri]; | pd = &amd_pmcdesc[ri]; | ||||
| if ((error = copystr(pd->pm_descr.pd_name, pi->pm_name, | strlcpy(pi->pm_name, pd->pm_descr.pd_name, PMC_NAME_MAX); | ||||
jkoshy: How about using `sizeof(pi->pm_name)` instead of `PMC_NAME_MAX`?
This would remove the need… | |||||
| PMC_NAME_MAX, &copied)) != 0) | |||||
| return error; | |||||
| pi->pm_class = pd->pm_descr.pd_class; | pi->pm_class = pd->pm_descr.pd_class; | ||||
| if (phw->phw_state & PMC_PHW_FLAG_IS_ENABLED) { | if (phw->phw_state & PMC_PHW_FLAG_IS_ENABLED) { | ||||
| pi->pm_enabled = TRUE; | pi->pm_enabled = TRUE; | ||||
| *ppmc = phw->phw_pmc; | *ppmc = phw->phw_pmc; | ||||
| } else { | } else { | ||||
| pi->pm_enabled = FALSE; | pi->pm_enabled = FALSE; | ||||
| *ppmc = NULL; | *ppmc = NULL; | ||||
| ▲ Show 20 Lines • Show All 313 Lines • Show Last 20 Lines | |||||
How about using sizeof(pi->pm_name) instead of PMC_NAME_MAX?
This would remove the need for the reader to check that the pm_name field is at least PMC_NAME_MAX in size.
Here and below.