From: Sarthak Sharma <sarthak.sharma@arm.com>
To: akpm@linux-foundation.org, david@kernel.org
Cc: ljs@kernel.org, liam@infradead.org, vbabka@suse.com,
rppt@kernel.org, surenb@google.com, mhocko@suse.com,
shuah@kernel.org, jhubbard@nvidia.com, kaleshsingh@google.com,
anshuman.khandual@arm.com, linux-mm@kvack.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
Sarthak Sharma <sarthak.sharma@arm.com>
Subject: [PATCH v2 03/12] selftests/mm: mremap_test: simplify errno handling
Date: Tue, 6 Oct 2026 14:55:02 +0530 [thread overview]
Message-ID: <20261006092511.145776-4-sarthak.sharma@arm.com> (raw)
In-Reply-To: <20261006092511.145776-1-sarthak.sharma@arm.com>
mremap_move_multi_invalid_vmas() saves and restores
errno around several checks even when no other function
call can change it. Remove these instances and compare
errno directly.
Also move perror() after the userfaultfd skip check
to avoid printing an error when the test is skipped.
Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Sarthak Sharma <sarthak.sharma@arm.com>
---
tools/testing/selftests/mm/mremap_test.c | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selftests/mm/mremap_test.c
index 95ce6563289c..7cf1d235f309 100644
--- a/tools/testing/selftests/mm/mremap_test.c
+++ b/tools/testing/selftests/mm/mremap_test.c
@@ -727,7 +727,7 @@ static void mremap_move_multi_invalid_vmas(FILE *maps_fp,
const size_t size = 10 * page_size;
bool success = true;
char *ptr, *tgt_ptr;
- int uffd, err, i;
+ int uffd, i;
void *res;
struct uffdio_api api = {
.api = UFFD_API,
@@ -736,12 +736,11 @@ static void mremap_move_multi_invalid_vmas(FILE *maps_fp,
uffd = syscall(__NR_userfaultfd, O_NONBLOCK);
if (uffd == -1) {
- err = errno;
- perror("userfaultfd");
- if (err == EPERM) {
+ if (errno == EPERM) {
ksft_test_result_skip("%s - missing uffd", test_name);
return;
}
+ perror("userfaultfd");
success = false;
goto out;
}
@@ -810,14 +809,12 @@ static void mremap_move_multi_invalid_vmas(FILE *maps_fp,
* time.
*/
res = mremap(ptr, size, size, MREMAP_MAYMOVE | MREMAP_FIXED, tgt_ptr);
- err = errno;
if (res != MAP_FAILED) {
fprintf(stderr, "mremap() succeeded for multi VMA uffd armed\n");
success = false;
goto out_unmap;
}
- if (err != EFAULT) {
- errno = err;
+ if (errno != EFAULT) {
perror("mremap() unexpected error");
success = false;
goto out_unmap;
@@ -863,14 +860,12 @@ static void mremap_move_multi_invalid_vmas(FILE *maps_fp,
* first VMA, but no others, and report a failure.
*/
res = mremap(ptr, size, size, MREMAP_MAYMOVE | MREMAP_FIXED, tgt_ptr);
- err = errno;
if (res != MAP_FAILED) {
fprintf(stderr, "mremap() succeeded for multi VMA uffd armed\n");
success = false;
goto out_unmap;
}
- if (err != EFAULT) {
- errno = err;
+ if (errno != EFAULT) {
perror("mremap() unexpected error");
success = false;
goto out_unmap;
@@ -912,14 +907,12 @@ static void mremap_move_multi_invalid_vmas(FILE *maps_fp,
* the last VMA, and report a failure.
*/
res = mremap(ptr, size, size, MREMAP_MAYMOVE | MREMAP_FIXED, tgt_ptr);
- err = errno;
if (res != MAP_FAILED) {
fprintf(stderr, "mremap() succeeded for multi VMA uffd armed\n");
success = false;
goto out_unmap;
}
- if (err != EFAULT) {
- errno = err;
+ if (errno != EFAULT) {
perror("mremap() unexpected error");
success = false;
goto out_unmap;
--
2.53.0
next prev parent reply other threads:[~2026-10-06 9:25 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 9:24 [PATCH v2 00/12] selftests/mm: improve mremap_test Sarthak Sharma
2026-10-06 9:25 ` [PATCH v2 01/12] selftests/mm: mremap_test: remove command line options Sarthak Sharma
2026-10-06 9:25 ` [PATCH v2 02/12] selftests/mm: mremap_test: drop munmap() checks from cleanup paths Sarthak Sharma
2026-10-06 9:25 ` Sarthak Sharma [this message]
2026-10-06 9:25 ` [PATCH v2 04/12] selftests/mm: mremap_test: use kselftest helpers Sarthak Sharma
2026-10-06 9:25 ` [PATCH v2 05/12] selftests/mm: mremap_test: skip test when userfaultfd is unavailable Sarthak Sharma
2026-10-06 9:25 ` [PATCH v2 06/12] selftests/mm: mremap_test: fail unexpected mremap successes Sarthak Sharma
2026-10-06 9:25 ` [PATCH v2 07/12] selftests/mm: mremap_test: fail on data corruption Sarthak Sharma
2026-10-06 9:25 ` [PATCH v2 08/12] selftests/mm: mremap_test: handle cleanup after mmap failures Sarthak Sharma
2026-10-06 9:25 ` [PATCH v2 09/12] selftests/mm: mremap_test: remove perf tests and timing Sarthak Sharma
2026-10-06 9:25 ` [PATCH v2 10/12] selftests/mm: mremap_test: replace validation threshold with sampled checks Sarthak Sharma
2026-10-06 9:25 ` [PATCH v2 11/12] selftests/mm: mremap_test: replace random data with deterministic pattern Sarthak Sharma
2026-10-06 9:25 ` [PATCH v2 12/12] selftests/mm: mremap_test: strengthen multi VMA validation Sarthak Sharma
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261006092511.145776-4-sarthak.sharma@arm.com \
--to=sarthak.sharma@arm.com \
--cc=akpm@linux-foundation.org \
--cc=anshuman.khandual@arm.com \
--cc=david@kernel.org \
--cc=jhubbard@nvidia.com \
--cc=kaleshsingh@google.com \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--cc=shuah@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®