selftests/resctrl: Clean up resctrl features check
[ Upstream commit 2428673638ea28fa93d2a38b1c3e8d70122b00ee ] Checking resctrl features call strcmp() to compare feature strings (e.g. "mba", "cat" etc). The checkings are error prone and don't have good coding style. Define the constant strings in macros and call strncmp() to solve the potential issues. Suggested-by: Shuah Khan <skhan@linuxfoundation.org> Tested-by: Babu Moger <babu.moger@amd.com> Signed-off-by: Fenghua Yu <fenghua.yu@intel.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
6ef95f0b80
commit
cd29eef127
@@ -397,10 +397,10 @@ static void initialize_mem_bw_resctrl(const char *ctrlgrp, const char *mongrp,
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(resctrl_val, "mbm") == 0)
|
||||
if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)))
|
||||
set_mbm_path(ctrlgrp, mongrp, resource_id);
|
||||
|
||||
if ((strcmp(resctrl_val, "mba") == 0)) {
|
||||
if (!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) {
|
||||
if (ctrlgrp)
|
||||
sprintf(mbm_total_path, CON_MBM_LOCAL_BYTES_PATH,
|
||||
RESCTRL_PATH, ctrlgrp, resource_id);
|
||||
@@ -524,7 +524,7 @@ static void initialize_llc_occu_resctrl(const char *ctrlgrp, const char *mongrp,
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(resctrl_val, "cqm") == 0)
|
||||
if (!strncmp(resctrl_val, CQM_STR, sizeof(CQM_STR)))
|
||||
set_cqm_path(ctrlgrp, mongrp, resource_id);
|
||||
}
|
||||
|
||||
@@ -579,8 +579,8 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param)
|
||||
if (strcmp(param->filename, "") == 0)
|
||||
sprintf(param->filename, "stdio");
|
||||
|
||||
if ((strcmp(resctrl_val, "mba")) == 0 ||
|
||||
(strcmp(resctrl_val, "mbm")) == 0) {
|
||||
if (!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR)) ||
|
||||
!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR))) {
|
||||
ret = validate_bw_report_request(param->bw_report);
|
||||
if (ret)
|
||||
return ret;
|
||||
@@ -674,15 +674,15 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param)
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
if ((strcmp(resctrl_val, "mbm") == 0) ||
|
||||
(strcmp(resctrl_val, "mba") == 0)) {
|
||||
if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) ||
|
||||
!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) {
|
||||
ret = initialize_mem_bw_imc();
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
initialize_mem_bw_resctrl(param->ctrlgrp, param->mongrp,
|
||||
param->cpu_no, resctrl_val);
|
||||
} else if (strcmp(resctrl_val, "cqm") == 0)
|
||||
} else if (!strncmp(resctrl_val, CQM_STR, sizeof(CQM_STR)))
|
||||
initialize_llc_occu_resctrl(param->ctrlgrp, param->mongrp,
|
||||
param->cpu_no, resctrl_val);
|
||||
|
||||
@@ -710,8 +710,8 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param)
|
||||
|
||||
/* Test runs until the callback setup() tells the test to stop. */
|
||||
while (1) {
|
||||
if ((strcmp(resctrl_val, "mbm") == 0) ||
|
||||
(strcmp(resctrl_val, "mba") == 0)) {
|
||||
if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) ||
|
||||
!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) {
|
||||
ret = param->setup(1, param);
|
||||
if (ret) {
|
||||
ret = 0;
|
||||
@@ -721,7 +721,7 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param)
|
||||
ret = measure_vals(param, &bw_resc_start);
|
||||
if (ret)
|
||||
break;
|
||||
} else if (strcmp(resctrl_val, "cqm") == 0) {
|
||||
} else if (!strncmp(resctrl_val, CQM_STR, sizeof(CQM_STR))) {
|
||||
ret = param->setup(1, param);
|
||||
if (ret) {
|
||||
ret = 0;
|
||||
|
Reference in New Issue
Block a user