xtensa: fix return_address [Linux 3.16.72]

This Linux kernel change "xtensa: fix return_address" is included in the Linux 3.16.72 release. This change is authored by Max Filippov <jcmvbkbc [at] gmail.com> on Thu Apr 4 11:08:40 2019 -0700. The commit for this change in Linux stable tree is 53fcf3e (patch) which is from upstream commit ada770b. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream ada770b.

xtensa: fix return_address

commit ada770b1e74a77fff2d5f539bf6c42c25f4784db upstream.

return_address returns the address that is one level higher in the call
stack than requested in its argument, because level 0 corresponds to its
caller's return address. Use requested level as the number of stack
frames to skip.

This fixes the address reported by might_sleep and friends.

Signed-off-by: Max Filippov <[email protected]>
Signed-off-by: Ben Hutchings <[email protected]>

There are 6 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 arch/xtensa/kernel/stacktrace.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/xtensa/kernel/stacktrace.c b/arch/xtensa/kernel/stacktrace.c
index 7d2c317..922525c 100644
--- a/arch/xtensa/kernel/stacktrace.c
+++ b/arch/xtensa/kernel/stacktrace.c
@@ -107,10 +107,14 @@ static int return_address_cb(struct stackframe *frame, void *data)
    return 1;
 }

+/*
+ * level == 0 is for the return address from the caller of this function,
+ * not from this function itself.
+ */
 unsigned long return_address(unsigned level)
 {
    struct return_addr_data r = {
-       .skip = level + 1,
+       .skip = level,
    };
    walk_stackframe(stack_pointer(NULL), return_address_cb, &r);
    return r.addr;

Leave a Reply

Your email address will not be published. Required fields are marked *