V4L/DVB: cx231xx: improve error handling
[wandboard.git] / arch / sh / kernel / return_address.c
blobcbf1dd5372b2d223f399ab884fd46bfbd83246d1
1 /*
2 * arch/sh/kernel/return_address.c
4 * Copyright (C) 2009 Matt Fleming
5 * Copyright (C) 2009 Paul Mundt
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <asm/dwarf.h>
15 #ifdef CONFIG_DWARF_UNWINDER
17 void *return_address(unsigned int depth)
19 struct dwarf_frame *frame;
20 unsigned long ra;
21 int i;
23 for (i = 0, frame = NULL, ra = 0; i <= depth; i++) {
24 struct dwarf_frame *tmp;
26 tmp = dwarf_unwind_stack(ra, frame);
28 if (frame)
29 dwarf_free_frame(frame);
31 frame = tmp;
33 if (!frame || !frame->return_addr)
34 break;
36 ra = frame->return_addr;
39 /* Failed to unwind the stack to the specified depth. */
40 WARN_ON(i != depth + 1);
42 if (frame)
43 dwarf_free_frame(frame);
45 return (void *)ra;
48 #else
50 void *return_address(unsigned int depth)
52 return NULL;
55 #endif
57 EXPORT_SYMBOL_GPL(return_address);