hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/tools/testing/selftests/mqueue/mq_perf_tests.c
....@@ -180,6 +180,9 @@
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 @@
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 @@
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 @@
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,16 +631,11 @@
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 }
630
-
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");
635639
636640 max_msgs = fopen(MAX_MSGS, "r+");
637641 max_msgsize = fopen(MAX_MSGSIZE, "r+");
....@@ -740,4 +744,9 @@
740744 sleep(1);
741745 }
742746 shutdown(0, "", 0);
747
+
748
+err_code:
749
+ CPU_FREE(cpu_set);
750
+ exit(1);
751
+
743752 }