Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 27 Apr 2026 01:18:36 +0000
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: f7bf9fd6199c - main - tests/tcp_hpts_test: Fix resource leaks
Message-ID:  <69eeb96c.25497.3455786a@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=f7bf9fd6199c99284dbc899928d8ad62861da414

commit f7bf9fd6199c99284dbc899928d8ad62861da414
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-04-27 01:17:36 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-04-27 01:17:36 +0000

    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
---
 sys/netinet/tcp_hpts_test.c | 27 ++++++++++++++++++++++-----
 1 file 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);
 }
 
 /*


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69eeb96c.25497.3455786a>