* [PATCH] selftests/net: use MAP_FAILED instead of (void *)-1 in tcp_mmap
@ 2026-07-22 1:51 longlong yan
2026-07-22 13:15 ` Joe Damato
0 siblings, 1 reply; 2+ messages in thread
From: longlong yan @ 2026-07-22 1:51 UTC (permalink / raw)
To: pabeni, kuba, davem
Cc: edumazet, netdev, linux-kselftest, linux-kernel, shuah, horms,
longlong yan
mmap() is documented to return MAP_FAILED on error, but tcp_mmap.c
compares the return value against (void *)-1 and (unsigned char *)-1.
Replace these with the standard MAP_FAILED macro for better readability
and type safety.
Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
---
tools/testing/selftests/net/tcp_mmap.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/net/tcp_mmap.c b/tools/testing/selftests/net/tcp_mmap.c
index 2544ae35d07a..487ae659a1f1 100644
--- a/tools/testing/selftests/net/tcp_mmap.c
+++ b/tools/testing/selftests/net/tcp_mmap.c
@@ -141,12 +141,12 @@ static void *mmap_large_buffer(size_t need, size_t *allocated)
buffer = mmap(NULL, sz, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0);
- if (buffer == (void *)-1) {
+ if (buffer == MAP_FAILED) {
sz = need;
buffer = mmap(NULL, sz, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE,
-1, 0);
- if (buffer != (void *)-1)
+ if (buffer != MAP_FAILED)
fprintf(stderr, "MAP_HUGETLB attempt failed, look at /sys/kernel/mm/hugepages for optimal performance\n");
}
*allocated = sz;
@@ -189,13 +189,13 @@ void *child_thread(void *arg)
fcntl(fd, F_SETFL, O_NDELAY);
buffer = mmap_large_buffer(chunk_size, &buffer_sz);
- if (buffer == (void *)-1) {
+ if (buffer == MAP_FAILED) {
perror("mmap");
goto error;
}
if (zflg) {
raddr = mmap(NULL, chunk_size + map_align, PROT_READ, flags, fd, 0);
- if (raddr == (void *)-1) {
+ if (raddr == MAP_FAILED) {
perror("mmap");
zflg = 0;
} else {
@@ -547,7 +547,7 @@ int main(int argc, char *argv[])
}
buffer = mmap_large_buffer(chunk_size, &buffer_sz);
- if (buffer == (unsigned char *)-1) {
+ if (buffer == MAP_FAILED) {
perror("mmap");
exit(1);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] selftests/net: use MAP_FAILED instead of (void *)-1 in tcp_mmap
2026-07-22 1:51 [PATCH] selftests/net: use MAP_FAILED instead of (void *)-1 in tcp_mmap longlong yan
@ 2026-07-22 13:15 ` Joe Damato
0 siblings, 0 replies; 2+ messages in thread
From: Joe Damato @ 2026-07-22 13:15 UTC (permalink / raw)
To: longlong yan
Cc: pabeni, kuba, davem, edumazet, netdev, linux-kselftest,
linux-kernel, shuah, horms
On Wed, Jul 22, 2026 at 09:51:29AM +0800, longlong yan wrote:
> mmap() is documented to return MAP_FAILED on error, but tcp_mmap.c
> compares the return value against (void *)-1 and (unsigned char *)-1.
>
> Replace these with the standard MAP_FAILED macro for better readability
> and type safety.
>
> Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
> ---
> tools/testing/selftests/net/tcp_mmap.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
Looks right to me. Not sure if it needs to be set with "net-next" in the
subject line to make which tree this targets more explicit?
Either way:
Reviewed-by: Joe Damato <joe@dama.to>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-22 13:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-22 1:51 [PATCH] selftests/net: use MAP_FAILED instead of (void *)-1 in tcp_mmap longlong yan
2026-07-22 13:15 ` Joe Damato
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox