selftests/net: use MAP_FAILED instead of (void *)-1 in tcp_mmap
Subsystems (3)
PATCH 1/1 selftests/net: use MAP_FAILED instead of (void *)-1 in tcp_mmap
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.
--- tools/testing/selftests/net/tcp_mmap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
tools/testing/selftests/net/tcp_mmap.c +5 -5
@@ -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 ); }
Signature · 1 line
2.43.0
Quoted 11 lines · longlong yan
mmap()is documented to returnMAP_FAILEDon error, buttcp_mmap.ccompares the return value against (void *)-1 and (unsigned char *)-1.Replace these with the standard
MAP_FAILEDmacro for better readability and type safety.Signed-off-by longlong yan <[email protected]>--- 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:
Eric Dumazet
Reviewed-byQuoted 14 lines · Joe Damato
Quoted 11 lines · longlong yan
mmap()is documented to returnMAP_FAILEDon error, buttcp_mmap.ccompares the return value against (void *)-1 and (unsigned char *)-1.Replace these with the standard
MAP_FAILEDmacro for better readability and type safety.Signed-off-by longlong yan <[email protected]>--- tools/testing/selftests/net/tcp_mmap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
Quoted 6 lines
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 <[email protected]>
Yeah, I doubt linux will ever use a different value than (void *)-1 for MAP_FAILED.
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Wed, 22 Jul 2026 09:51:29 +0800 you wrote:
mmap()is documented to returnMAP_FAILEDon error, buttcp_mmap.ccompares the return value against (void *)-1 and (unsigned char *)-1.Replace these with the standard
MAP_FAILEDmacro for better readability and type safety.Signed-off-by longlong yan <[email protected]>[...]
Here is the summary with links:
- selftests/net: use MAP_FAILED instead of (void *)-1 in tcp_mmap
https://git.kernel.org/netdev/net-next/c/94cdc6a2c837
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html