diff mbox series

[v3,03/16] selftests/resctrl: Fix closing IMC fds on error

Message ID 20240408163247.3224-4-ilpo.jarvinen@linux.intel.com (mailing list archive)
State New
Headers show
Series selftests/resctrl: resctrl_val() related cleanups & improvements | expand

Commit Message

Ilpo Järvinen April 8, 2024, 4:32 p.m. UTC
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 mbox series

Patch

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;
 }
 
 /*