lkml.org 
[lkml]   [2024]   [Apr]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v3 03/16] selftests/resctrl: Fix closing IMC fds on error
Date
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;
}

/*
--
2.39.2

\
 
 \ /
  Last update: 2024-04-08 18:33    [W:0.076 / U:1.160 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site