diff mbox

[v3] arm: fix a wrong value returned from CALLER_ADDRn

Message ID 1363235701-21342-1-git-send-email-kpark3469@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

kpark3469@gmail.com March 14, 2013, 4:35 a.m. UTC
From: Sahara <keun-o.park@windriver.com>

This makes return_address() return a correct value for CALLER_ADDRn.
To have a correct value from CALLER_ADDRn, we need to fix three points.

* The unwind_frame() does not update frame->lr but frame->pc for backtrace.
So frame->pc is meaningful for backtrace.

* data.level should be adjusted by adding 2 additional iteration levels.
With the current +1 level adjustment, the result of CALLER_ADDR1 will
be the same return address with CALLER_ADDR0.

* The initialization of data.addr to NULL is needed.
When unwind_fame() fails right after data.level reaches zero,
the routine returns data.addr which has uninitialized garbage value.

Signed-off-by: Sahara <keun-o.park@windriver.com>
Reviewed-by: Dave Martin <dave.martin@linaro.org>
---
 arch/arm/kernel/return_address.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

Comments

Russell King - ARM Linux March 15, 2013, 5:34 p.m. UTC | #1
On Thu, Mar 14, 2013 at 01:35:01PM +0900, kpark3469@gmail.com wrote:
> From: Sahara <keun-o.park@windriver.com>
> 
> This makes return_address() return a correct value for CALLER_ADDRn.
> To have a correct value from CALLER_ADDRn, we need to fix three points.
> 
> * The unwind_frame() does not update frame->lr but frame->pc for backtrace.
> So frame->pc is meaningful for backtrace.
> 
> * data.level should be adjusted by adding 2 additional iteration levels.
> With the current +1 level adjustment, the result of CALLER_ADDR1 will
> be the same return address with CALLER_ADDR0.
> 
> * The initialization of data.addr to NULL is needed.
> When unwind_fame() fails right after data.level reaches zero,
> the routine returns data.addr which has uninitialized garbage value.
> 
> Signed-off-by: Sahara <keun-o.park@windriver.com>
> Reviewed-by: Dave Martin <dave.martin@linaro.org>

Please send this to the patch system.  I think we should let this sit
in -next for a bit (which we'll get anyway) to see what the effect is.
diff mbox

Patch

diff --git a/arch/arm/kernel/return_address.c b/arch/arm/kernel/return_address.c
index 8085417..fafedd8 100644
--- a/arch/arm/kernel/return_address.c
+++ b/arch/arm/kernel/return_address.c
@@ -26,7 +26,7 @@  static int save_return_addr(struct stackframe *frame, void *d)
 	struct return_address_data *data = d;
 
 	if (!data->level) {
-		data->addr = (void *)frame->lr;
+		data->addr = (void *)frame->pc;
 
 		return 1;
 	} else {
@@ -41,7 +41,8 @@  void *return_address(unsigned int level)
 	struct stackframe frame;
 	register unsigned long current_sp asm ("sp");
 
-	data.level = level + 1;
+	data.level = level + 2;
+	data.addr = NULL;
 
 	frame.fp = (unsigned long)__builtin_frame_address(0);
 	frame.sp = current_sp;