Skip to content

Commit 6cb4ac8

Browse files
athira-rajeevsmb49
authored andcommitted
testing/selftests/mqueue: Fix mq_perf_tests to free the allocated cpu set
BugLink: https://bugs.launchpad.net/bugs/1973085 [ Upstream commit ce64763 ] The selftest "mqueue/mq_perf_tests.c" use CPU_ALLOC to allocate CPU set. This cpu set is used further in pthread_attr_setaffinity_np and by pthread_create in the code. But in current code, allocated cpu set is not freed. Fix this issue by adding CPU_FREE in the "shutdown" function which is called in most of the error/exit path for the cleanup. There are few error paths which exit without using shutdown. Add a common goto error path with CPU_FREE for these cases. Fixes: 7820b07 ("tools/selftests: add mq_perf_tests") Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Kamal Mostafa <kamal@canonical.com> Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
1 parent c72d541 commit 6cb4ac8

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

tools/testing/selftests/mqueue/mq_perf_tests.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ void shutdown(int exit_val, char *err_cause, int line_no)
180180
if (in_shutdown++)
181181
return;
182182

183+
/* Free the cpu_set allocated using CPU_ALLOC in main function */
184+
CPU_FREE(cpu_set);
185+
183186
for (i = 0; i < num_cpus_to_pin; i++)
184187
if (cpu_threads[i]) {
185188
pthread_kill(cpu_threads[i], SIGUSR1);
@@ -551,6 +554,12 @@ int main(int argc, char *argv[])
551554
perror("sysconf(_SC_NPROCESSORS_ONLN)");
552555
exit(1);
553556
}
557+
558+
if (getuid() != 0)
559+
ksft_exit_skip("Not running as root, but almost all tests "
560+
"require root in order to modify\nsystem settings. "
561+
"Exiting.\n");
562+
554563
cpus_online = min(MAX_CPUS, sysconf(_SC_NPROCESSORS_ONLN));
555564
cpu_set = CPU_ALLOC(cpus_online);
556565
if (cpu_set == NULL) {
@@ -589,7 +598,7 @@ int main(int argc, char *argv[])
589598
cpu_set)) {
590599
fprintf(stderr, "Any given CPU may "
591600
"only be given once.\n");
592-
exit(1);
601+
goto err_code;
593602
} else
594603
CPU_SET_S(cpus_to_pin[cpu],
595604
cpu_set_size, cpu_set);
@@ -607,7 +616,7 @@ int main(int argc, char *argv[])
607616
queue_path = malloc(strlen(option) + 2);
608617
if (!queue_path) {
609618
perror("malloc()");
610-
exit(1);
619+
goto err_code;
611620
}
612621
queue_path[0] = '/';
613622
queue_path[1] = 0;
@@ -622,17 +631,12 @@ int main(int argc, char *argv[])
622631
fprintf(stderr, "Must pass at least one CPU to continuous "
623632
"mode.\n");
624633
poptPrintUsage(popt_context, stderr, 0);
625-
exit(1);
634+
goto err_code;
626635
} else if (!continuous_mode) {
627636
num_cpus_to_pin = 1;
628637
cpus_to_pin[0] = cpus_online - 1;
629638
}
630639

631-
if (getuid() != 0)
632-
ksft_exit_skip("Not running as root, but almost all tests "
633-
"require root in order to modify\nsystem settings. "
634-
"Exiting.\n");
635-
636640
max_msgs = fopen(MAX_MSGS, "r+");
637641
max_msgsize = fopen(MAX_MSGSIZE, "r+");
638642
if (!max_msgs)
@@ -740,4 +744,9 @@ int main(int argc, char *argv[])
740744
sleep(1);
741745
}
742746
shutdown(0, "", 0);
747+
748+
err_code:
749+
CPU_FREE(cpu_set);
750+
exit(1);
751+
743752
}

0 commit comments

Comments
 (0)