From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,vbabka@kernel.org,surenb@google.com,shuah@kernel.org,rppt@kernel.org,mhocko@suse.com,ljs@kernel.org,liam@infradead.org,david@kernel.org,yanlonglong@kylinos.cn,akpm@linux-foundation.org
Subject: + selftests-mm-use-map_failed-for-mmap-error-check.patch added to mm-new branch
Date: Mon, 20 Jul 2026 16:47:48 -0700 [thread overview]
Message-ID: <20260720234748.C50F61F000E9@smtp.kernel.org> (raw)
The patch titled
Subject: selftests/mm: use MAP_FAILED for mmap error check
has been added to the -mm mm-new branch. Its filename is
selftests-mm-use-map_failed-for-mmap-error-check.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/selftests-mm-use-map_failed-for-mmap-error-check.patch
This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews. Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.
The mm-new branch of mm.git is not included in linux-next
If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: longlong yan <yanlonglong@kylinos.cn>
Subject: selftests/mm: use MAP_FAILED for mmap error check
Date: Mon, 20 Jul 2026 14:34:39 +0800
Replace the direct comparison with (void *)-1 with the standard MAP_FAILED
macro when checking mmap()
Link: https://lore.kernel.org/20260720063439.522-1-yanlonglong@kylinos.cn
Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
tools/testing/selftests/mm/mseal_test.c | 106 +++++++++++-----------
1 file changed, 53 insertions(+), 53 deletions(-)
--- a/tools/testing/selftests/mm/mseal_test.c~selftests-mm-use-map_failed-for-mmap-error-check
+++ a/tools/testing/selftests/mm/mseal_test.c
@@ -234,7 +234,7 @@ static void test_seal_addseal(void)
unsigned long size = 4 * page_size;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
ret = sys_mseal(ptr, size);
FAIL_TEST_IF_FALSE(!ret);
@@ -250,7 +250,7 @@ static void test_seal_unmapped_start(voi
unsigned long size = 4 * page_size;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
/* munmap 2 pages from ptr. */
ret = sys_munmap(ptr, 2 * page_size);
@@ -278,7 +278,7 @@ static void test_seal_unmapped_middle(vo
unsigned long size = 4 * page_size;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
/* munmap 2 pages from ptr + page. */
ret = sys_munmap(ptr + page_size, 2 * page_size);
@@ -310,7 +310,7 @@ static void test_seal_unmapped_end(void)
unsigned long size = 4 * page_size;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
/* unmap last 2 pages. */
ret = sys_munmap(ptr + 2 * page_size, 2 * page_size);
@@ -339,7 +339,7 @@ static void test_seal_multiple_vmas(void
unsigned long size = 4 * page_size;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
/* use mprotect to split the vma into 3. */
ret = sys_mprotect(ptr + page_size, 2 * page_size,
@@ -370,7 +370,7 @@ static void test_seal_split_start(void)
unsigned long size = 4 * page_size;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
/* use mprotect to split at middle */
ret = sys_mprotect(ptr, 2 * page_size, PROT_READ | PROT_WRITE);
@@ -395,7 +395,7 @@ static void test_seal_split_end(void)
unsigned long size = 4 * page_size;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
/* use mprotect to split at middle */
ret = sys_mprotect(ptr, 2 * page_size, PROT_READ | PROT_WRITE);
@@ -420,7 +420,7 @@ static void test_seal_invalid_input(void
int ret;
setup_single_address(8 * page_size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
ret = clean_single_address(ptr + 4 * page_size, 4 * page_size);
FAIL_TEST_IF_FALSE(!ret);
@@ -455,7 +455,7 @@ static void test_seal_zero_length(void)
int ret;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
ret = sys_mprotect(ptr, 0, PROT_READ | PROT_WRITE);
FAIL_TEST_IF_FALSE(!ret);
@@ -505,7 +505,7 @@ static void test_seal_twice(void)
unsigned long size = 4 * page_size;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
ret = sys_mseal(ptr, size);
FAIL_TEST_IF_FALSE(!ret);
@@ -525,7 +525,7 @@ static void test_seal_mprotect(bool seal
int ret;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
if (seal) {
ret = seal_single_address(ptr, size);
@@ -549,7 +549,7 @@ static void test_seal_start_mprotect(boo
int ret;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
if (seal) {
ret = seal_single_address(ptr, page_size);
@@ -579,7 +579,7 @@ static void test_seal_end_mprotect(bool
int ret;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
if (seal) {
ret = seal_single_address(ptr + page_size, 3 * page_size);
@@ -609,7 +609,7 @@ static void test_seal_mprotect_unalign_l
int ret;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
if (seal) {
ret = seal_single_address(ptr, page_size * 2 - 1);
@@ -638,7 +638,7 @@ static void test_seal_mprotect_unalign_l
int ret;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
if (seal) {
ret = seal_single_address(ptr, page_size * 2 + 1);
FAIL_TEST_IF_FALSE(!ret);
@@ -666,7 +666,7 @@ static void test_seal_mprotect_two_vma(b
int ret;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
/* use mprotect to split */
ret = sys_mprotect(ptr, page_size * 2, PROT_READ | PROT_WRITE);
@@ -701,7 +701,7 @@ static void test_seal_mprotect_two_vma_w
int ret;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
/* use mprotect to split as two vma. */
ret = sys_mprotect(ptr, page_size * 2, PROT_READ | PROT_WRITE);
@@ -748,7 +748,7 @@ static void test_seal_mprotect_partial_m
int ret;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
/* seal one page. */
if (seal) {
@@ -780,7 +780,7 @@ static void test_seal_mprotect_partial_m
*/
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
if (seal) {
ret = sys_mseal(ptr + page_size, page_size);
@@ -810,7 +810,7 @@ static void test_seal_mprotect_two_vma_w
int ret;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
/* use mprotect to split. */
ret = sys_mprotect(ptr, page_size, PROT_READ | PROT_WRITE);
@@ -853,7 +853,7 @@ static void test_seal_mprotect_split(boo
int ret;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
/* use mprotect to split. */
ret = sys_mprotect(ptr, page_size, PROT_READ | PROT_WRITE);
@@ -890,7 +890,7 @@ static void test_seal_mprotect_merge(boo
int ret;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
/* use mprotect to split one page. */
ret = sys_mprotect(ptr, page_size, PROT_READ | PROT_WRITE);
@@ -924,7 +924,7 @@ static void test_seal_munmap(bool seal)
int ret;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
if (seal) {
ret = sys_mseal(ptr, size);
@@ -955,7 +955,7 @@ static void test_seal_munmap_two_vma(boo
int ret;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
/* use mprotect to split */
ret = sys_mprotect(ptr, page_size * 2, PROT_READ | PROT_WRITE);
@@ -996,7 +996,7 @@ static void test_seal_munmap_vma_with_ga
int ret;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
ret = sys_munmap(ptr + page_size, page_size * 2);
FAIL_TEST_IF_FALSE(!ret);
@@ -1028,7 +1028,7 @@ static void test_seal_munmap_partial_acr
int prot;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
if (seal) {
ret = sys_mseal(ptr + page_size, page_size);
@@ -1058,7 +1058,7 @@ static void test_munmap_start_freed(bool
int prot;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
/* unmap the first page. */
ret = sys_munmap(ptr, page_size);
@@ -1097,7 +1097,7 @@ static void test_munmap_end_freed(bool s
int ret;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
/* unmap last page. */
ret = sys_munmap(ptr + page_size * 3, page_size);
@@ -1128,7 +1128,7 @@ static void test_munmap_middle_freed(boo
int prot;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
/* unmap 2 pages in the middle. */
ret = sys_munmap(ptr + page_size, page_size * 2);
@@ -1172,7 +1172,7 @@ static void test_seal_mremap_shrink(bool
void *ret2;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
if (seal) {
ret = sys_mseal(ptr, size);
@@ -1201,7 +1201,7 @@ static void test_seal_mremap_expand(bool
void *ret2;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
/* ummap last 2 pages. */
ret = sys_munmap(ptr + 2 * page_size, 2 * page_size);
FAIL_TEST_IF_FALSE(!ret);
@@ -1233,9 +1233,9 @@ static void test_seal_mremap_move(bool s
void *ret2;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
setup_single_address(size, &newPtr);
- FAIL_TEST_IF_FALSE(newPtr != (void *)-1);
+ FAIL_TEST_IF_FALSE(newPtr != MAP_FAILED);
ret = clean_single_address(newPtr, size);
FAIL_TEST_IF_FALSE(!ret);
@@ -1266,7 +1266,7 @@ static void test_seal_mmap_overwrite_pro
void *ret2;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
if (seal) {
ret = sys_mseal(ptr, size);
@@ -1294,7 +1294,7 @@ static void test_seal_mmap_expand(bool s
void *ret2;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
/* ummap last 4 pages. */
ret = sys_munmap(ptr + 8 * page_size, 4 * page_size);
FAIL_TEST_IF_FALSE(!ret);
@@ -1325,7 +1325,7 @@ static void test_seal_mmap_shrink(bool s
void *ret2;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
if (seal) {
ret = sys_mseal(ptr, size);
@@ -1354,9 +1354,9 @@ static void test_seal_mremap_shrink_fixe
void *ret2;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
setup_single_address(size, &newAddr);
- FAIL_TEST_IF_FALSE(newAddr != (void *)-1);
+ FAIL_TEST_IF_FALSE(newAddr != MAP_FAILED);
if (seal) {
ret = sys_mseal(ptr, size);
@@ -1385,9 +1385,9 @@ static void test_seal_mremap_expand_fixe
void *ret2;
setup_single_address(page_size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
setup_single_address(size, &newAddr);
- FAIL_TEST_IF_FALSE(newAddr != (void *)-1);
+ FAIL_TEST_IF_FALSE(newAddr != MAP_FAILED);
if (seal) {
ret = sys_mseal(newAddr, size);
@@ -1416,9 +1416,9 @@ static void test_seal_mremap_move_fixed(
void *ret2;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
setup_single_address(size, &newAddr);
- FAIL_TEST_IF_FALSE(newAddr != (void *)-1);
+ FAIL_TEST_IF_FALSE(newAddr != MAP_FAILED);
if (seal) {
ret = sys_mseal(newAddr, size);
@@ -1445,7 +1445,7 @@ static void test_seal_mremap_move_fixed_
void *ret2;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
if (seal) {
ret = sys_mseal(ptr, size);
@@ -1476,7 +1476,7 @@ static void test_seal_mremap_move_dontun
void *ret2;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
if (seal) {
ret = sys_mseal(ptr, size);
@@ -1505,7 +1505,7 @@ static void test_seal_mremap_move_dontun
void *ret2;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
if (seal) {
ret = sys_mseal(ptr, size);
@@ -1517,7 +1517,7 @@ static void test_seal_mremap_move_dontun
* use allocate/free to similate that.
*/
setup_single_address(size, &ptr2);
- FAIL_TEST_IF_FALSE(ptr2 != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr2 != MAP_FAILED);
ret = sys_munmap(ptr2, size);
FAIL_TEST_IF_FALSE(!ret);
@@ -1547,7 +1547,7 @@ static void test_seal_merge_and_split(vo
/* (24 RO) */
setup_single_address(24 * page_size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
/* use mprotect(NONE) to set out boundary */
/* (1 NONE) (22 RO) (1 NONE) */
@@ -1637,7 +1637,7 @@ static void test_seal_discard_ro_anon_on
int ret;
setup_single_address_rw(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
if (seal) {
ret = sys_mseal(ptr, size);
@@ -1669,7 +1669,7 @@ static void test_seal_discard_ro_anon_on
SKIP_TEST_IF_FALSE(pkey_supported());
setup_single_address_rw(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
pkey = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
FAIL_TEST_IF_FALSE(pkey > 0);
@@ -1751,7 +1751,7 @@ static void test_seal_discard_ro_anon_on
unsigned long mapflags = MAP_ANONYMOUS | MAP_SHARED;
ptr = mmap(NULL, size, PROT_READ, mapflags, -1, 0);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
if (seal) {
ret = sys_mseal(ptr, size);
@@ -1779,7 +1779,7 @@ static void test_seal_discard_ro_anon(bo
int ret;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
if (seal) {
ret = seal_single_address(ptr, size);
@@ -1809,7 +1809,7 @@ static void test_seal_discard_across_vma
int ret;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
if (seal) {
ret = seal_single_address(ptr + page_size, page_size);
@@ -1840,7 +1840,7 @@ static void test_seal_madvise_nodiscard(
int ret;
setup_single_address(size, &ptr);
- FAIL_TEST_IF_FALSE(ptr != (void *)-1);
+ FAIL_TEST_IF_FALSE(ptr != MAP_FAILED);
if (seal) {
ret = seal_single_address(ptr, size);
_
Patches currently in -mm which might be from yanlonglong@kylinos.cn are
selftests-mm-use-map_failed-for-mmap-error-check.patch
reply other threads:[~2026-07-20 23:47 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260720234748.C50F61F000E9@smtp.kernel.org \
--to=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=liam@infradead.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=mm-commits@vger.kernel.org \
--cc=rppt@kernel.org \
--cc=shuah@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=yanlonglong@kylinos.cn \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.