[PATCH v2 1/4] selftests/futex: Let futex_waitv() take no timeout

From: Mathieu Desnoyers

Date: Sun Nov 08 2026 - 09:50:08 EST


The futex_waitv() helper of futex2test.h copies the caller's timeout
into a struct __kernel_timespec. It dereferences the pointer without a
check, so a caller cannot pass NULL. The syscall takes NULL as no
timeout.

Pass NULL to the syscall when the caller passes NULL. The futex_waitv
tests use this in a later patch, to wait until they are woken.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
---
tools/testing/selftests/futex/include/futex2test.h | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/futex/include/futex2test.h b/tools/testing/selftests/futex/include/futex2test.h
index 53e88b60ac6d..a4616b6edcff 100644
--- a/tools/testing/selftests/futex/include/futex2test.h
+++ b/tools/testing/selftests/futex/include/futex2test.h
@@ -68,12 +68,16 @@ struct futex32_numa {
static inline int futex_waitv(volatile struct futex_waitv *waiters, unsigned long nr_waiters,
unsigned long flags, struct timespec *timo, clockid_t clockid)
{
- struct __kernel_timespec ts = {
- .tv_sec = timo->tv_sec,
- .tv_nsec = timo->tv_nsec,
- };
+ struct __kernel_timespec ts, *tsp = NULL;

- return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, &ts, clockid);
+ /* No timeout: wait until woken. */
+ if (timo) {
+ ts.tv_sec = timo->tv_sec;
+ ts.tv_nsec = timo->tv_nsec;
+ tsp = &ts;
+ }
+
+ return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, tsp, clockid);
}

/*
--
2.47.3