aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2026-04-27 01:17:36 +0000
committerMark Johnston <markj@FreeBSD.org>2026-04-27 01:17:36 +0000
commitf7bf9fd6199c99284dbc899928d8ad62861da414 (patch)
tree2e08b01d628150214046a4bd1002f616bf69520c
parent92e5f6e1995acb10628ab210cc9f19dbf74f2948 (diff)
tests/tcp_hpts_test: Fix resource leaks
When a KTEST_EQUAL assertion fails, the test function returns, but this can cause it to leak locks, which can trigger a panic under witness. Add a variant which causes control flow to jump to a label in case of failure, and use that to prevent this problem. Reviewed by: Nick Banks <nickbanks@netflix.com>, tuexen MFC after: 1 weeks Differential Revision: https://reviews.freebsd.org/D56647
-rw-r--r--sys/netinet/tcp_hpts_test.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/sys/netinet/tcp_hpts_test.c b/sys/netinet/tcp_hpts_test.c
index a664e9fafcc3..bc61b64b8c58 100644
--- a/sys/netinet/tcp_hpts_test.c
+++ b/sys/netinet/tcp_hpts_test.c
@@ -90,6 +90,18 @@ SYSCTL_INT(_net_inet_tcp_hpts_test, OID_AUTO, exit_on_failure, CTLFLAG_RW,
} \
} while (0)
+#define KTEST_EQUAL_GOTO(x, y, label) do { \
+ if ((x) != (y)) { \
+ KTEST_ERR(ctx, "FAIL: %s != %s (%d != %d)", #x, #y, (x), (y)); \
+ if (test_exit_on_failure) { \
+ error = EINVAL; \
+ goto label; \
+ } \
+ } else { \
+ KTEST_LOG(ctx, "PASS: %s == %s", #x, #y); \
+ } \
+} while (0)
+
#define KTEST_NEQUAL(x, y) do { \
if ((x) == (y)) { \
KTEST_ERR(ctx, "FAIL: %s == %s (%d == %d)", #x, #y, (x), (y)); \
@@ -1461,6 +1473,7 @@ KTEST_FUNC(direct_wake_mechanism)
struct tcp_hptsi *pace;
struct tcpcb *tp;
struct tcp_hpts_entry *hpts;
+ int error;
test_hpts_init();
@@ -1477,8 +1490,8 @@ KTEST_FUNC(direct_wake_mechanism)
hpts->p_on_queue_cnt = 50; /* Below threshold */
hpts->p_hpts_wake_scheduled = 0;
tcp_hpts_wake(hpts);
- KTEST_EQUAL(hpts->p_hpts_wake_scheduled, 1);
- KTEST_EQUAL(call_counts[CCNT_SWI_SCHED], 1);
+ KTEST_EQUAL_GOTO(hpts->p_hpts_wake_scheduled, 1, cleanup_locked);
+ KTEST_EQUAL_GOTO(call_counts[CCNT_SWI_SCHED], 1, cleanup_locked);
HPTS_UNLOCK(hpts);
/* Reset for next test */
@@ -1490,9 +1503,9 @@ KTEST_FUNC(direct_wake_mechanism)
hpts->p_on_queue_cnt = 200; /* Above threshold */
hpts->p_direct_wake = 1; /* Request direct wake */
tcp_hpts_wake(hpts);
- KTEST_EQUAL(hpts->p_hpts_wake_scheduled, 0); /* Should be inhibited */
- KTEST_EQUAL(hpts->p_direct_wake, 0); /* Should be cleared */
- KTEST_EQUAL(call_counts[CCNT_SWI_SCHED], 0); /* No SWI scheduled */
+ KTEST_EQUAL_GOTO(hpts->p_hpts_wake_scheduled, 0, cleanup_locked);
+ KTEST_EQUAL_GOTO(hpts->p_direct_wake, 0, cleanup_locked);
+ KTEST_EQUAL_GOTO(call_counts[CCNT_SWI_SCHED], 0, cleanup_locked);
HPTS_UNLOCK(hpts);
test_hpts_free_tcpcb(tp);
@@ -1500,6 +1513,10 @@ KTEST_FUNC(direct_wake_mechanism)
tcp_hptsi_destroy(pace);
return (0);
+
+cleanup_locked:
+ HPTS_UNLOCK(hpts);
+ return (error);
}
/*