* [PATCH] Fix the bool convert to int issue
@ 2021-09-18 7:30 cgel.zte
2021-09-18 8:20 ` Peter Zijlstra
0 siblings, 1 reply; 2+ messages in thread
From: cgel.zte @ 2021-09-18 7:30 UTC (permalink / raw)
To: peterz
Cc: jpoimboe, jbaron, rostedt, ardb, tglx, mingo, bp, x86, hpa,
linux-kernel, Yang Guang
From: Yang Guang <yang.guang5@zte.com.cn>
The int value which convert from bool true is 0xFFFFFFFF. Causing the
__sc_insn return wrong type.
Signed-off-by: Yang Guang <yang.guang5@zte.com.cn>
---
arch/x86/kernel/static_call.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kernel/static_call.c b/arch/x86/kernel/static_call.c
index ea028e736831..f608e6710300 100644
--- a/arch/x86/kernel/static_call.c
+++ b/arch/x86/kernel/static_call.c
@@ -89,7 +89,7 @@ static inline enum insn_type __sc_insn(bool null, bool tail)
* 1 | 0 | JMP
* 1 | 1 | RET
*/
- return 2*tail + null;
+ return ((tail)?2:0) + ((null)?1:0);
}
void arch_static_call_transform(void *site, void *tramp, void *func, bool tail)
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix the bool convert to int issue
2021-09-18 7:30 [PATCH] Fix the bool convert to int issue cgel.zte
@ 2021-09-18 8:20 ` Peter Zijlstra
0 siblings, 0 replies; 2+ messages in thread
From: Peter Zijlstra @ 2021-09-18 8:20 UTC (permalink / raw)
To: cgel.zte
Cc: jpoimboe, jbaron, rostedt, ardb, tglx, mingo, bp, x86, hpa,
linux-kernel, Yang Guang, Greg Kroah-Hartman
On Sat, Sep 18, 2021 at 07:30:37AM +0000, cgel.zte@gmail.com wrote:
> From: Yang Guang <yang.guang5@zte.com.cn>
>
> The int value which convert from bool true is 0xFFFFFFFF. Causing the
> __sc_insn return wrong type.
Aaah, this is where the insanity starts...
My copy of the C spec says:
"When any scalar value is converted to _Bool, the result is 0 if the
value compares equal to 0; otherwise, the result is 1."
What does yours say?
Also, did your kernel boot? If what you say is right it would've gone up
in flames a long time ago.
Please, learn C _before_ sending patches.
*plonk*
>
> Signed-off-by: Yang Guang <yang.guang5@zte.com.cn>
> ---
> arch/x86/kernel/static_call.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/static_call.c b/arch/x86/kernel/static_call.c
> index ea028e736831..f608e6710300 100644
> --- a/arch/x86/kernel/static_call.c
> +++ b/arch/x86/kernel/static_call.c
> @@ -89,7 +89,7 @@ static inline enum insn_type __sc_insn(bool null, bool tail)
> * 1 | 0 | JMP
> * 1 | 1 | RET
> */
> - return 2*tail + null;
> + return ((tail)?2:0) + ((null)?1:0);
> }
>
> void arch_static_call_transform(void *site, void *tramp, void *func, bool tail)
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-09-18 8:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-18 7:30 [PATCH] Fix the bool convert to int issue cgel.zte
2021-09-18 8:20 ` Peter Zijlstra
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.