Impact: fix of test if an address is 26 bits away or not

Paul Mackerras pointed out that the test of the 24bit offset jump was
incorrect. For one thing, it is a 26 bit distance since we multiply
by 4 to account for the alignment. Another is that it may produce an
incorrect result on a negative jump of exactly the offset size.

Reported-by: Paul Mackerras <[EMAIL PROTECTED]>
Signed-off-by: Steven Rostedt <[EMAIL PROTECTED]>
---
 arch/powerpc/kernel/ftrace.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/ftrace.c b/arch/powerpc/kernel/ftrace.c
index 9360fd1..918a5d2 100644
--- a/arch/powerpc/kernel/ftrace.c
+++ b/arch/powerpc/kernel/ftrace.c
@@ -114,12 +114,19 @@ ftrace_modify_code(unsigned long ip, unsigned char 
*old_code,
  */
 static int test_24bit_addr(unsigned long ip, unsigned long addr)
 {
-       unsigned long diff;
+       long diff;
 
-       /* can we get to addr from ip in 24 bits? */
-       diff = ip > addr ? ip - addr : addr - ip;
+       /*
+        * Can we get to addr from ip in 24 bits?
+        *  (26 really, since we mulitply by 4 for 4 byte alignment)
+        */
+       diff = addr - ip;
 
-       return !(diff & ((unsigned long)-1 << 24));
+       /*
+        * Return true if diff is less than 1 << 25
+        *  and greater than -1 << 26.
+        */
+       return (diff < (1 << 25)) && (diff > (-1 << 26));
 }
 
 static int is_bl_op(unsigned int op)
-- 
1.5.6.5

-- 
_______________________________________________
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev

Reply via email to