[tip: timers/core] selftests: timers: nanosleep: Explicitly handle timer_delete() failure

From: tip-bot2 for Thomas Weißschuh (Schneider Electric)

Date: Tue Aug 11 2026 - 12:26:32 EST


The following commit has been merged into the timers/core branch of tip:

Commit-ID: f2ff28a52255f04ab0de16a7d298e35360852890
Gitweb: https://git.kernel.org/tip/f2ff28a52255f04ab0de16a7d298e35360852890
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@xxxxxxxxxxxxx>
AuthorDate: Mon, 03 Aug 2026 12:04:43 +02:00
Committer: Thomas Gleixner <tglx@xxxxxxxxxx>
CommitterDate: Tue, 11 Aug 2026 18:11:21 +02:00

selftests: timers: nanosleep: Explicitly handle timer_delete() failure

An upcoming patch will remove the early exit on failure of a single
testcase. If a test fails because a timeout timer could not be deleted,
then that timeout timer might interfere with the following tettcases.

Exit the whole test case with a clear error message in this case.

Other failures are not problematic:
* If timer_settime() fails, a harmless unarmed timer is left around.
* The SIGALRM handler reconfigured for each call to
nanosleep_test_remaining() anyways.

Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@xxxxxxxxxxxxx>
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxx>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-12-910cbd485390@xxxxxxxxxxxxx
---
tools/testing/selftests/timers/nanosleep.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/selftests/timers/nanosleep.c
index 5037481..dd899dc 100644
--- a/tools/testing/selftests/timers/nanosleep.c
+++ b/tools/testing/selftests/timers/nanosleep.c
@@ -111,11 +111,14 @@ static int nanosleep_test_remaining(int clockid)

rqtp.tv_nsec = NSEC_PER_SEC / 2;
ret = clock_nanosleep(clockid, 0, &rqtp, &rmtp);
- if (ret != EINTR)
- return KSFT_FAIL;

- ret = timer_delete(timer);
- if (ret)
+ if (timer_delete(timer)) {
+ ksft_exit_fail_msg("Unable to delete the timeout timer for %s. "
+ "This might interfere with following testcases.\n",
+ clock_name(clockid));
+ }
+
+ if (ret != EINTR)
return KSFT_FAIL;

sa.sa_handler = SIG_DFL;