[PATCH] selftests/sgx: use MAP_FAILED for mmap error check

longlong yan posted 1 patch 4 days, 23 hours ago
tools/testing/selftests/sgx/load.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] selftests/sgx: use MAP_FAILED for mmap error check
Posted by longlong yan 4 days, 23 hours ago
Replace the direct comparison with (void *)-1 with the standard
MAP_FAILED macro when checking mmap()

Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
---
 tools/testing/selftests/sgx/load.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/sgx/load.c b/tools/testing/selftests/sgx/load.c
index c9f658e44de6..6204ab0bae19 100644
--- a/tools/testing/selftests/sgx/load.c
+++ b/tools/testing/selftests/sgx/load.c
@@ -202,7 +202,7 @@ bool encl_load(const char *path, struct encl *encl, unsigned long heap_size)
 	}
 
 	ptr = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, fd, 0);
-	if (ptr == (void *)-1) {
+	if (ptr == MAP_FAILED) {
 		perror("mmap for read");
 		goto err;
 	}
@@ -215,7 +215,7 @@ bool encl_load(const char *path, struct encl *encl, unsigned long heap_size)
 " If so, remount it executable: mount -o remount,exec /dev\n\n"
 
 	ptr = mmap(NULL, PAGE_SIZE, PROT_EXEC, MAP_SHARED, fd, 0);
-	if (ptr == (void *)-1) {
+	if (ptr == MAP_FAILED) {
 		fprintf(stderr, ERR_MSG);
 		goto err;
 	}
-- 
2.43.0
Re: [PATCH] selftests/sgx: use MAP_FAILED for mmap error check
Posted by Jarkko Sakkinen 2 days, 11 hours ago
On Mon, Jul 20, 2026 at 10:54:43AM +0800, longlong yan wrote:
> Replace the direct comparison with (void *)-1 with the standard
> MAP_FAILED macro when checking mmap()
> 
> Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
> ---
>  tools/testing/selftests/sgx/load.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/sgx/load.c b/tools/testing/selftests/sgx/load.c
> index c9f658e44de6..6204ab0bae19 100644
> --- a/tools/testing/selftests/sgx/load.c
> +++ b/tools/testing/selftests/sgx/load.c
> @@ -202,7 +202,7 @@ bool encl_load(const char *path, struct encl *encl, unsigned long heap_size)
>  	}
>  
>  	ptr = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, fd, 0);
> -	if (ptr == (void *)-1) {
> +	if (ptr == MAP_FAILED) {
>  		perror("mmap for read");
>  		goto err;
>  	}
> @@ -215,7 +215,7 @@ bool encl_load(const char *path, struct encl *encl, unsigned long heap_size)
>  " If so, remount it executable: mount -o remount,exec /dev\n\n"
>  
>  	ptr = mmap(NULL, PAGE_SIZE, PROT_EXEC, MAP_SHARED, fd, 0);
> -	if (ptr == (void *)-1) {
> +	if (ptr == MAP_FAILED) {
>  		fprintf(stderr, ERR_MSG);
>  		goto err;
>  	}
> -- 
> 2.43.0
> 

Yeah, why not:

Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

It does document test cases better.

BR, Jarkko
Re: [PATCH] selftests/sgx: use MAP_FAILED for mmap error check
Posted by Huang, Kai 3 days ago
On Mon, 2026-07-20 at 10:54 +0800, longlong yan wrote:
> Replace the direct comparison with (void *)-1 with the standard
> MAP_FAILED macro when checking mmap()

This sentence misses the ending period.

> 
> Signed-off-by: longlong yan <yanlonglong@kylinos.cn>

Acked-by: Kai Huang <kai.huang@intel.com>