]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
selftests/vm: fix errno handling in mrelease_test
authorAdam Sindelar <adam@wowsignal.io>
Mon, 4 Jul 2022 17:33:51 +0000 (19:33 +0200)
committerakpm <akpm@linux-foundation.org>
Wed, 20 Jul 2022 21:41:46 +0000 (14:41 -0700)
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.

Link: https://lkml.kernel.org/r/20220704173351.19595-1-adam@wowsignal.io
Fixes: 33776141b812 ("selftests: vm: add process_mrelease tests")
Signed-off-by: Adam Sindelar <adam@wowsignal.io>
Reviewed-by: David Vernet <void@manifault.com>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/testing/selftests/vm/mrelease_test.c

index 96671c2f7d48595ee3c97ea8f5c35d2816e500ec..e8b17258579ba7cb559965e1aff924d342c924bf 100644 (file)
@@ -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 */
@@ -156,8 +158,9 @@ retry:
        run_negative_tests(pidfd);
 
        if (kill(pid, SIGKILL)) {
+               res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
                perror("kill");
-               exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
+               exit(res);
        }
 
        success = (syscall(__NR_process_mrelease, pidfd, 0) == 0);