]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
selftests-vm-fix-errno-handling-in-mrelease_test-v4
authorAdam Sindelar <adam@wowsignal.io>
Wed, 6 Jul 2022 14:16:02 +0000 (16:16 +0200)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Wed, 3 Aug 2022 18:17:10 +0000 (14:17 -0400)
fix remaining instances of errno mishandling

Link: https://lkml.kernel.org/r/20220706141602.10159-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 e8b17258579ba7cb559965e1aff924d342c924bf..6c62966ab5dbcb44214ab05f772f9f5f8dcef7e1 100644 (file)
@@ -62,19 +62,22 @@ static int alloc_noexit(unsigned long nr_pages, int pipefd)
 /* The process_mrelease calls in this test are expected to fail */
 static void run_negative_tests(int pidfd)
 {
+       int res;
        /* Test invalid flags. Expect to fail with EINVAL error code. */
        if (!syscall(__NR_process_mrelease, pidfd, (unsigned int)-1) ||
                        errno != EINVAL) {
+               res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
                perror("process_mrelease with wrong flags");
-               exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
+               exit(res);
        }
        /*
         * Test reaping while process is alive with no pending SIGKILL.
         * Expect to fail with EINVAL error code.
         */
        if (!syscall(__NR_process_mrelease, pidfd, 0) || errno != EINVAL) {
+               res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
                perror("process_mrelease on a live process");
-               exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
+               exit(res);
        }
 }
 
@@ -100,7 +103,6 @@ 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(res);
@@ -175,9 +177,10 @@ retry:
                if (errno == ESRCH) {
                        retry = (size <= MAX_SIZE_MB);
                } else {
+                       res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
                        perror("process_mrelease");
                        waitpid(pid, NULL, 0);
-                       exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL);
+                       exit(res);
                }
        }