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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxx>
---

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





[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux