Patchwork [2/2] powerpc: make ftrace endian-safe.

login
register
mail settings
Submitter Eugene Surovegin
Date Sept. 20, 2013, 6:42 p.m.
Message ID <1379702541-28372-2-git-send-email-ebs@ebshome.net>
Download mbox | patch
Permalink /patch/276601/
State Accepted, archived
Commit 306474304fdfe3723562a02226c0a44e8078d3a0
Delegated to: Benjamin Herrenschmidt
Headers show

Comments

Eugene Surovegin - Sept. 20, 2013, 6:42 p.m.
Signed-off-by: Eugene Surovegin <surovegin@google.com>
---
 arch/powerpc/kernel/ftrace.c | 4 ++++
 1 file changed, 4 insertions(+)
David Laight - Sept. 23, 2013, 8:33 a.m.
> --- a/arch/powerpc/kernel/ftrace.c
> +++ b/arch/powerpc/kernel/ftrace.c
> @@ -174,7 +174,11 @@ __ftrace_make_nop(struct module *mod,
> 
>  	pr_devel(" %08x %08x\n", jmp[0], jmp[1]);
> 
> +#ifdef __LITTLE_ENDIAN__
> +	ptr = ((unsigned long)jmp[1] << 32) + jmp[0];
> +#else
>  	ptr = ((unsigned long)jmp[0] << 32) + jmp[1];
> +#endif
> 

Why not just:
	ptr = *(__u64 *)jmp;

Or, if alignment isn't guaranteed, something that is
equivalent to:
	ptr = *(__u64 __attribute__((aligned(4))) *)jmp;

	David

Patch

diff --git a/arch/powerpc/kernel/ftrace.c b/arch/powerpc/kernel/ftrace.c
index 1fb7856..9b27b29 100644
--- a/arch/powerpc/kernel/ftrace.c
+++ b/arch/powerpc/kernel/ftrace.c
@@ -174,7 +174,11 @@  __ftrace_make_nop(struct module *mod,
 
 	pr_devel(" %08x %08x\n", jmp[0], jmp[1]);
 
+#ifdef __LITTLE_ENDIAN__
+	ptr = ((unsigned long)jmp[1] << 32) + jmp[0];
+#else
 	ptr = ((unsigned long)jmp[0] << 32) + jmp[1];
+#endif
 
 	/* This should match what was called */
 	if (ptr != ppc_function_entry((void *)addr)) {