* [PATCH] selftests/powerpc: use MAP_FAILED instead of (void *)-1 in tm-signal-context-force-tm
@ 2026-07-22 2:34 longlong yan
2026-07-22 9:39 ` Amit Machhiwal
0 siblings, 1 reply; 2+ messages in thread
From: longlong yan @ 2026-07-22 2:34 UTC (permalink / raw)
To: maddy, mpe
Cc: npiggin, chleroy, linuxppc-dev, linux-kselftest, shuah,
linux-kernel, longlong yan
mmap() is documented to return MAP_FAILED on error, but
tm-signal-context-force-tm.c compares the return value against
(void *)-1. Replace these with the standard MAP_FAILED macro for
better readability and type safety.
Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
---
.../testing/selftests/powerpc/tm/tm-signal-context-force-tm.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/powerpc/tm/tm-signal-context-force-tm.c b/tools/testing/selftests/powerpc/tm/tm-signal-context-force-tm.c
index 0a4bc479ae39..5dc0f12f467d 100644
--- a/tools/testing/selftests/powerpc/tm/tm-signal-context-force-tm.c
+++ b/tools/testing/selftests/powerpc/tm/tm-signal-context-force-tm.c
@@ -60,7 +60,7 @@ void usr_signal_handler(int signo, siginfo_t *si, void *uc)
ucp->uc_link = mmap(NULL, sizeof(ucontext_t),
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
- if (ucp->uc_link == (void *)-1) {
+ if (ucp->uc_link == MAP_FAILED) {
perror("Mmap failed");
exit(-1);
}
@@ -129,7 +129,7 @@ void tm_trap_test(void)
ss.ss_size = SIGSTKSZ;
ss.ss_flags = 0;
- if (ss.ss_sp == (void *)-1) {
+ if (ss.ss_sp == MAP_FAILED) {
perror("mmap error\n");
exit(-1);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] selftests/powerpc: use MAP_FAILED instead of (void *)-1 in tm-signal-context-force-tm
2026-07-22 2:34 [PATCH] selftests/powerpc: use MAP_FAILED instead of (void *)-1 in tm-signal-context-force-tm longlong yan
@ 2026-07-22 9:39 ` Amit Machhiwal
0 siblings, 0 replies; 2+ messages in thread
From: Amit Machhiwal @ 2026-07-22 9:39 UTC (permalink / raw)
To: longlong yan
Cc: maddy, mpe, npiggin, chleroy, linuxppc-dev, linux-kselftest,
shuah, linux-kernel
On 2026/07/22 10:34 AM, longlong yan wrote:
> mmap() is documented to return MAP_FAILED on error, but
> tm-signal-context-force-tm.c compares the return value against
> (void *)-1. Replace these with the standard MAP_FAILED macro for
> better readability and type safety.
The mmap man page does confirm:
RETURN VALUE
On success, mmap() returns a pointer to the mapped area. On
error, the value MAP_FAILED (that is, (void *) -1) is returned,
and errno is set to indicate the error.
So, the MAP_FAILED substitution looks correct. Please feel free to add:
Reviewed-by: Amit Machhiwal <amachhiw@linux.ibm.com>
Thanks,
Amit
>
> Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
> ---
> .../testing/selftests/powerpc/tm/tm-signal-context-force-tm.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/powerpc/tm/tm-signal-context-force-tm.c b/tools/testing/selftests/powerpc/tm/tm-signal-context-force-tm.c
> index 0a4bc479ae39..5dc0f12f467d 100644
> --- a/tools/testing/selftests/powerpc/tm/tm-signal-context-force-tm.c
> +++ b/tools/testing/selftests/powerpc/tm/tm-signal-context-force-tm.c
> @@ -60,7 +60,7 @@ void usr_signal_handler(int signo, siginfo_t *si, void *uc)
> ucp->uc_link = mmap(NULL, sizeof(ucontext_t),
> PROT_READ | PROT_WRITE,
> MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
> - if (ucp->uc_link == (void *)-1) {
> + if (ucp->uc_link == MAP_FAILED) {
> perror("Mmap failed");
> exit(-1);
> }
> @@ -129,7 +129,7 @@ void tm_trap_test(void)
> ss.ss_size = SIGSTKSZ;
> ss.ss_flags = 0;
>
> - if (ss.ss_sp == (void *)-1) {
> + if (ss.ss_sp == MAP_FAILED) {
> perror("mmap error\n");
> exit(-1);
> }
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-22 9:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-22 2:34 [PATCH] selftests/powerpc: use MAP_FAILED instead of (void *)-1 in tm-signal-context-force-tm longlong yan
2026-07-22 9:39 ` Amit Machhiwal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox