All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tools: Strong conversion of void type pointer could be removed
@ 2022-06-27  8:56 Li kunyu
  2022-06-27 19:57 ` Shuah Khan
  0 siblings, 1 reply; 4+ messages in thread
From: Li kunyu @ 2022-06-27  8:56 UTC (permalink / raw)
  To: shuah; +Cc: linux-kselftest, linux-kernel, Li kunyu

The void pointer argument does not require a cast assignment because it
is the address passed.

Signed-off-by: Li kunyu <kunyu@nfschina.com>
---
 tools/testing/selftests/x86/fsgsbase.c      | 2 +-
 tools/testing/selftests/x86/test_vsyscall.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/x86/fsgsbase.c b/tools/testing/selftests/x86/fsgsbase.c
index 8c780cce941d..5d99261317e1 100644
--- a/tools/testing/selftests/x86/fsgsbase.c
+++ b/tools/testing/selftests/x86/fsgsbase.c
@@ -63,7 +63,7 @@ static void clearhandler(int sig)
 
 static void sigsegv(int sig, siginfo_t *si, void *ctx_void)
 {
-	ucontext_t *ctx = (ucontext_t*)ctx_void;
+	ucontext_t *ctx = ctx_void;
 
 	if (!want_segv) {
 		clearhandler(SIGSEGV);
diff --git a/tools/testing/selftests/x86/test_vsyscall.c b/tools/testing/selftests/x86/test_vsyscall.c
index 5b45e6986aea..2416941a0952 100644
--- a/tools/testing/selftests/x86/test_vsyscall.c
+++ b/tools/testing/selftests/x86/test_vsyscall.c
@@ -184,7 +184,7 @@ static volatile unsigned long segv_err;
 
 static void sigsegv(int sig, siginfo_t *info, void *ctx_void)
 {
-	ucontext_t *ctx = (ucontext_t *)ctx_void;
+	ucontext_t *ctx = ctx_void;
 
 	segv_err =  ctx->uc_mcontext.gregs[REG_ERR];
 	siglongjmp(jmpbuf, 1);
-- 
2.18.2


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

* Re: [PATCH] tools: Strong conversion of void type pointer could be removed
  2022-06-27  8:56 [PATCH] tools: Strong conversion of void type pointer could be removed Li kunyu
@ 2022-06-27 19:57 ` Shuah Khan
  2022-06-29  2:42   ` Li kunyu
  0 siblings, 1 reply; 4+ messages in thread
From: Shuah Khan @ 2022-06-27 19:57 UTC (permalink / raw)
  To: Li kunyu, shuah; +Cc: linux-kselftest, linux-kernel, Shuah Khan

On 6/27/22 2:56 AM, Li kunyu wrote:
> The void pointer argument does not require a cast assignment because it
> is the address passed.
> 

Please include information on you found this problem with output
from the tool if any used. Send v2 with that information included
in the commit log.

> Signed-off-by: Li kunyu <kunyu@nfschina.com>
> ---
>   tools/testing/selftests/x86/fsgsbase.c      | 2 +-
>   tools/testing/selftests/x86/test_vsyscall.c | 2 +-
>   2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/x86/fsgsbase.c b/tools/testing/selftests/x86/fsgsbase.c
> index 8c780cce941d..5d99261317e1 100644
> --- a/tools/testing/selftests/x86/fsgsbase.c
> +++ b/tools/testing/selftests/x86/fsgsbase.c
> @@ -63,7 +63,7 @@ static void clearhandler(int sig)
>   
>   static void sigsegv(int sig, siginfo_t *si, void *ctx_void)
>   {
> -	ucontext_t *ctx = (ucontext_t*)ctx_void;
> +	ucontext_t *ctx = ctx_void;
>   
>   	if (!want_segv) {
>   		clearhandler(SIGSEGV);
> diff --git a/tools/testing/selftests/x86/test_vsyscall.c b/tools/testing/selftests/x86/test_vsyscall.c
> index 5b45e6986aea..2416941a0952 100644
> --- a/tools/testing/selftests/x86/test_vsyscall.c
> +++ b/tools/testing/selftests/x86/test_vsyscall.c
> @@ -184,7 +184,7 @@ static volatile unsigned long segv_err;
>   
>   static void sigsegv(int sig, siginfo_t *info, void *ctx_void)
>   {
> -	ucontext_t *ctx = (ucontext_t *)ctx_void;
> +	ucontext_t *ctx = ctx_void;
>   
>   	segv_err =  ctx->uc_mcontext.gregs[REG_ERR];
>   	siglongjmp(jmpbuf, 1);
> 

thanks,
-- Shuah

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

* Re: [PATCH] tools: Strong conversion of void type pointer could be removed
  2022-06-27 19:57 ` Shuah Khan
@ 2022-06-29  2:42   ` Li kunyu
  2022-06-29 23:09     ` Shuah Khan
  0 siblings, 1 reply; 4+ messages in thread
From: Li kunyu @ 2022-06-29  2:42 UTC (permalink / raw)
  To: skhan; +Cc: kunyu, linux-kernel, linux-kselftest, shuah


Hi Shuah, now I can't paste the test code, so I could write a demo and paste it:


-------------source---------------

#include <stdio.h>
#include <stdlib.h>

struct ucontext {
	struct ucontext         *uc_link;
	unsigned long           uc_flags;
	sigset_t                uc_sigmask;
	struct ucontext         *uc_mcontext;
};
typedef struct ucontext ucontext_t;

void sigsegv(void *ctx_void)
{
	ucontext_t *ctx = (ucontext_t*)ctx_void;
	ucontext_t *ctx2 = (int *)ctx_void;
	ucontext_t *ctx3 = ctx_void;
	printf("ctx:%p, ctx2:%p, ctx3:%p.\n", ctx, ctx2, ctx3);
}

int main() {
	ucontext_t *test = malloc(sizeof(ucontext_t));
	sigsegv(test);
	return 0;
}

--------------------------------------

The result is CTX: 0x563D96CE5010, CTX2:0x563D96CE5010, CTx3:0x563D96CE5010.
Now force ucontext_t and int pointers are the same as the addresses obtained without forced conversion.

Now I'll paste the assembly code for them:


|0x700 <sigsegv>         push   %rbp                                                  │
│0x701 <sigsegv+1>       mov    %rsp,%rbp                                             │
│0x704 <sigsegv+4>       sub    $0x30,%rsp                                            │
│0x708 <sigsegv+8>       mov    %rdi,-0x28(%rbp)                                      │
│0x70c <sigsegv+12>      mov    -0x28(%rbp),%rax                                      │
│0x710 <sigsegv+16>      mov    %rax,-0x8(%rbp)                                       │
│0x714 <sigsegv+20>      mov    -0x28(%rbp),%rax                                      │
│0x718 <sigsegv+24>      mov    %rax,-0x10(%rbp)                                      │
│0x71c <sigsegv+28>      mov    -0x28(%rbp),%rax                                      │
│0x720 <sigsegv+32>      mov    %rax,-0x18(%rbp)                                      │
│0x724 <sigsegv+36>      mov    -0x18(%rbp),%rcx                                      │
│0x728 <sigsegv+40>      mov    -0x10(%rbp),%rdx                                      │
│0x72c <sigsegv+44>      mov    -0x8(%rbp),%rax                                       │
│0x730 <sigsegv+48>      mov    %rax,%rsi                                             │
│0x733 <sigsegv+51>      lea    0xba(%rip),%rdi        # 0x7f4                        │
│0x73a <sigsegv+58>      mov    $0x0,%eax                                             │
│0x73f <sigsegv+63>      callq  0x5a0 <printf@plt>                                    │
│0x744 <sigsegv+68>      nop                                                          │
│0x745 <sigsegv+69>      leaveq                                                       │
│0x746 <sigsegv+70>      retq


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

* Re: [PATCH] tools: Strong conversion of void type pointer could be removed
  2022-06-29  2:42   ` Li kunyu
@ 2022-06-29 23:09     ` Shuah Khan
  0 siblings, 0 replies; 4+ messages in thread
From: Shuah Khan @ 2022-06-29 23:09 UTC (permalink / raw)
  To: Li kunyu; +Cc: linux-kernel, linux-kselftest, shuah, Shuah Khan

On 6/28/22 8:42 PM, Li kunyu wrote:
> 
> Hi Shuah, now I can't paste the test code, so I could write a demo and paste it:
> 
> 

What is the "test code"?

How did you find the problem? Which tool did you use it?

thanks,
-- Shuah

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

end of thread, other threads:[~2022-06-29 23:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-27  8:56 [PATCH] tools: Strong conversion of void type pointer could be removed Li kunyu
2022-06-27 19:57 ` Shuah Khan
2022-06-29  2:42   ` Li kunyu
2022-06-29 23:09     ` Shuah Khan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.