If perf_open_imc_mem_bw() fails to open for a perf fd after the first one, the already opened fds remain open and error is directly returned.
Close the fds inside perf_open_imc_mem_bw() if an error occurs.
Fixes: 7f4d257e3a2a ("selftests/resctrl: Add callback to start a benchmark") Signed-off-by: Ilpo Järvinen ilpo.jarvinen@linux.intel.com ---
v3: - New patch --- tools/testing/selftests/resctrl/resctrl_val.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index ca4da7f4cf25..f2b6824cd5f2 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -306,13 +306,23 @@ static int perf_open_imc_mem_bw(int cpu_no) for (imc = 0; imc < imcs; imc++) { ret = open_perf_event(imc, cpu_no, READ); if (ret) - return -1; + goto close_fds; ret = open_perf_event(imc, cpu_no, WRITE); if (ret) - return -1; + goto close_read_fd; }
return 0; + +close_read_fd: + close(imc_counters_config[imc][READ].fd); +close_fds: + while (imc--) { + close(imc_counters_config[imc][READ].fd); + close(imc_counters_config[imc][WRITE].fd); + } + + return -1; }
/*