selftests/resctrl: Clean up resctrl features check
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>
This commit is contained in:
@@ -334,7 +334,7 @@ void run_benchmark(int signum, siginfo_t *info, void *ucontext)
|
||||
operation = atoi(benchmark_cmd[4]);
|
||||
sprintf(resctrl_val, "%s", benchmark_cmd[5]);
|
||||
|
||||
if (strcmp(resctrl_val, "cqm") != 0)
|
||||
if (strncmp(resctrl_val, CQM_STR, sizeof(CQM_STR)))
|
||||
buffer_span = span * MB;
|
||||
else
|
||||
buffer_span = span;
|
||||
@@ -459,8 +459,8 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp,
|
||||
goto out;
|
||||
|
||||
/* Create mon grp and write pid into it for "mbm" and "cqm" test */
|
||||
if ((strcmp(resctrl_val, "cqm") == 0) ||
|
||||
(strcmp(resctrl_val, "mbm") == 0)) {
|
||||
if (!strncmp(resctrl_val, CQM_STR, sizeof(CQM_STR)) ||
|
||||
!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR))) {
|
||||
if (strlen(mongrp)) {
|
||||
sprintf(monitorgroup_p, "%s/mon_groups", controlgroup);
|
||||
sprintf(monitorgroup, "%s/%s", monitorgroup_p, mongrp);
|
||||
@@ -505,9 +505,9 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val)
|
||||
int resource_id, ret = 0;
|
||||
FILE *fp;
|
||||
|
||||
if ((strcmp(resctrl_val, "mba") != 0) &&
|
||||
(strcmp(resctrl_val, "cat") != 0) &&
|
||||
(strcmp(resctrl_val, "cqm") != 0))
|
||||
if (strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR)) &&
|
||||
strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR)) &&
|
||||
strncmp(resctrl_val, CQM_STR, sizeof(CQM_STR)))
|
||||
return -ENOENT;
|
||||
|
||||
if (!schemata) {
|
||||
@@ -528,9 +528,10 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val)
|
||||
else
|
||||
sprintf(controlgroup, "%s/schemata", RESCTRL_PATH);
|
||||
|
||||
if (!strcmp(resctrl_val, "cat") || !strcmp(resctrl_val, "cqm"))
|
||||
if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR)) ||
|
||||
!strncmp(resctrl_val, CQM_STR, sizeof(CQM_STR)))
|
||||
sprintf(schema, "%s%d%c%s", "L3:", resource_id, '=', schemata);
|
||||
if (strcmp(resctrl_val, "mba") == 0)
|
||||
if (!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR)))
|
||||
sprintf(schema, "%s%d%c%s", "MB:", resource_id, '=', schemata);
|
||||
|
||||
fp = fopen(controlgroup, "w");
|
||||
|
||||
Reference in New Issue
Block a user