Skip to content

Commit d14d94d

Browse files
ij-intelshuahkh
authored andcommitted
selftests/resctrl: Convert ctrlgrp & mongrp to pointers
The struct resctrl_val_param has control and monitor groups as char arrays but they are not supposed to be mutated within resctrl_val(). Convert the ctrlgrp and mongrp char array within resctrl_val_param to plain const char pointers and adjust the strlen() based checks to check NULL instead. Signed-off-by: Ilpo Järvinen <[email protected]> Tested-by: Babu Moger <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 909592b commit d14d94d

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

tools/testing/selftests/resctrl/resctrl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ struct resctrl_test {
9191
*/
9292
struct resctrl_val_param {
9393
char *resctrl_val;
94-
char ctrlgrp[64];
95-
char mongrp[64];
94+
const char *ctrlgrp;
95+
const char *mongrp;
9696
char filename[64];
9797
unsigned long mask;
9898
int num_of_runs;

tools/testing/selftests/resctrl/resctrlfs.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,9 @@ int taskset_restore(pid_t bm_pid, cpu_set_t *old_affinity)
456456
* @grp: Full path and name of the group
457457
* @parent_grp: Full path and name of the parent group
458458
*
459+
* Creates a group @grp_name if it does not exist yet. If @grp_name is NULL,
460+
* it is interpreted as the root group which always results in success.
461+
*
459462
* Return: 0 on success, < 0 on error.
460463
*/
461464
static int create_grp(const char *grp_name, char *grp, const char *parent_grp)
@@ -464,12 +467,7 @@ static int create_grp(const char *grp_name, char *grp, const char *parent_grp)
464467
struct dirent *ep;
465468
DIR *dp;
466469

467-
/*
468-
* At this point, we are guaranteed to have resctrl FS mounted and if
469-
* length of grp_name == 0, it means, user wants to use root con_mon
470-
* grp, so do nothing
471-
*/
472-
if (strlen(grp_name) == 0)
470+
if (!grp_name)
473471
return 0;
474472

475473
/* Check if requested grp exists or not */
@@ -541,7 +539,7 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, const char *ctrlgrp,
541539
char tasks[1024];
542540
int ret = 0;
543541

544-
if (strlen(ctrlgrp))
542+
if (ctrlgrp)
545543
sprintf(controlgroup, "%s/%s", RESCTRL_PATH, ctrlgrp);
546544
else
547545
sprintf(controlgroup, "%s", RESCTRL_PATH);
@@ -558,7 +556,7 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, const char *ctrlgrp,
558556
/* Create mon grp and write pid into it for "mbm" and "cmt" test */
559557
if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR)) ||
560558
!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR))) {
561-
if (strlen(mongrp)) {
559+
if (mongrp) {
562560
sprintf(monitorgroup_p, "%s/mon_groups", controlgroup);
563561
sprintf(monitorgroup, "%s/%s", monitorgroup_p, mongrp);
564562
ret = create_grp(mongrp, monitorgroup, monitorgroup_p);
@@ -612,7 +610,7 @@ int write_schemata(const char *ctrlgrp, char *schemata, int cpu_no,
612610
goto out;
613611
}
614612

615-
if (strlen(ctrlgrp) != 0)
613+
if (ctrlgrp)
616614
sprintf(controlgroup, "%s/%s/schemata", RESCTRL_PATH, ctrlgrp);
617615
else
618616
sprintf(controlgroup, "%s/schemata", RESCTRL_PATH);

0 commit comments

Comments
 (0)