The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] selftests/sgx: use MAP_FAILED for mmap error check
@ 2026-07-20  2:54 longlong yan
  2026-07-22  2:17 ` Huang, Kai
  2026-07-22 15:33 ` Jarkko Sakkinen
  0 siblings, 2 replies; 3+ messages in thread
From: longlong yan @ 2026-07-20  2:54 UTC (permalink / raw)
  To: jarkko, dave.hansen, shuah, linux-sgx, linux-kselftest,
	linux-kernel
  Cc: longlong yan

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests/sgx: use MAP_FAILED for mmap error check
  2026-07-20  2:54 [PATCH] selftests/sgx: use MAP_FAILED for mmap error check longlong yan
@ 2026-07-22  2:17 ` Huang, Kai
  2026-07-22 15:33 ` Jarkko Sakkinen
  1 sibling, 0 replies; 3+ messages in thread
From: Huang, Kai @ 2026-07-22  2:17 UTC (permalink / raw)
  To: linux-sgx@vger.kernel.org, shuah@kernel.org, jarkko@kernel.org,
	linux-kselftest@vger.kernel.org, yanlonglong@kylinos.cn,
	dave.hansen@linux.intel.com, linux-kernel@vger.kernel.org

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>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests/sgx: use MAP_FAILED for mmap error check
  2026-07-20  2:54 [PATCH] selftests/sgx: use MAP_FAILED for mmap error check longlong yan
  2026-07-22  2:17 ` Huang, Kai
@ 2026-07-22 15:33 ` Jarkko Sakkinen
  1 sibling, 0 replies; 3+ messages in thread
From: Jarkko Sakkinen @ 2026-07-22 15:33 UTC (permalink / raw)
  To: longlong yan; +Cc: dave.hansen, shuah, linux-sgx, linux-kselftest, linux-kernel

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-22 15:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-20  2:54 [PATCH] selftests/sgx: use MAP_FAILED for mmap error check longlong yan
2026-07-22  2:17 ` Huang, Kai
2026-07-22 15:33 ` Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox