linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests/vm: fix errno handling in mrelease_test
@ 2022-07-04 17:26 Adam Sindelar
  0 siblings, 0 replies; only message in thread
From: Adam Sindelar @ 2022-07-04 17:26 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, Adam Sindelar, Adam Sindelar, David Vernet, kernel-team

mrelease_test should return KSFT_SKIP when process_mrelease is not
defined, but due to a perror call consuming the errno, it returns
KSFT_FAIL.

This patch decides the exit code before calling perror.

Signed-off-by: Adam Sindelar <adam@wowsignal.io>
---
 tools/testing/selftests/vm/mrelease_test.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/vm/mrelease_test.c b/tools/testing/selftests/vm/mrelease_test.c
index 96671c2f7d48..bdf49a0af3f6 100644
--- a/tools/testing/selftests/vm/mrelease_test.c
+++ b/tools/testing/selftests/vm/mrelease_test.c
@@ -100,8 +100,10 @@ int main(void)
 
 	/* Test a wrong pidfd */
 	if (!syscall(__NR_process_mrelease, -1, 0) || errno != EBADF) {
+		/* perror overwrites errno, so this line must be first */
+		res = errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL;
 		perror("process_mrelease with wrong pidfd");
-		exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
+		exit(res);
 	}
 
 	/* Start the test with 1MB child memory allocation */
-- 
2.35.1



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-04 17:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-04 17:26 [PATCH] selftests/vm: fix errno handling in mrelease_test Adam Sindelar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).