Linux 6.13-rc4
[linux.git] / arch / sh / kernel / return_address.c
blob2ce22f11eab37839c6f4c07765a17324f59e203d
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * arch/sh/kernel/return_address.c
5 * Copyright (C) 2009 Matt Fleming
6 * Copyright (C) 2009 Paul Mundt
7 */
8 #include <linux/kernel.h>
9 #include <linux/module.h>
11 #include <asm/dwarf.h>
12 #include <asm/ftrace.h>
14 #ifdef CONFIG_DWARF_UNWINDER
16 void *return_address(unsigned int depth)
18 struct dwarf_frame *frame;
19 unsigned long ra;
20 int i;
22 for (i = 0, frame = NULL, ra = 0; i <= depth; i++) {
23 struct dwarf_frame *tmp;
25 tmp = dwarf_unwind_stack(ra, frame);
26 if (!tmp)
27 return NULL;
29 if (frame)
30 dwarf_free_frame(frame);
32 frame = tmp;
34 if (!frame || !frame->return_addr)
35 break;
37 ra = frame->return_addr;
40 /* Failed to unwind the stack to the specified depth. */
41 WARN_ON(i != depth + 1);
43 if (frame)
44 dwarf_free_frame(frame);
46 return (void *)ra;
49 #else
51 void *return_address(unsigned int depth)
53 return NULL;
56 #endif
58 EXPORT_SYMBOL_GPL(return_address);