Merge tag 'sched-urgent-2020-12-27' of git://git.kernel.org/pub/scm/linux/kernel...
[linux/fpc-iii.git] / arch / sh / kernel / return_address.c
blob8838094c9ff9444fadf5ceef6f6210772f8cb279
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>
10 #include <asm/dwarf.h>
12 #ifdef CONFIG_DWARF_UNWINDER
14 void *return_address(unsigned int depth)
16 struct dwarf_frame *frame;
17 unsigned long ra;
18 int i;
20 for (i = 0, frame = NULL, ra = 0; i <= depth; i++) {
21 struct dwarf_frame *tmp;
23 tmp = dwarf_unwind_stack(ra, frame);
24 if (!tmp)
25 return NULL;
27 if (frame)
28 dwarf_free_frame(frame);
30 frame = tmp;
32 if (!frame || !frame->return_addr)
33 break;
35 ra = frame->return_addr;
38 /* Failed to unwind the stack to the specified depth. */
39 WARN_ON(i != depth + 1);
41 if (frame)
42 dwarf_free_frame(frame);
44 return (void *)ra;
47 #else
49 void *return_address(unsigned int depth)
51 return NULL;
54 #endif
56 EXPORT_SYMBOL_GPL(return_address);