Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bug: Factor out a getter for a bug's file line

There is some non-trivial config-based logic to get the file name and
line number associated with a bug. Factor this out to a getter that can
be resused.

Signed-off-by: Andrew Scull <ascull@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Acked-by: Will Deacon <will@kernel.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20210318143311.839894-3-ascull@google.com

authored by

Andrew Scull and committed by
Marc Zyngier
26dbc7e2 3ad1a6cb

+20 -10
+3
include/linux/bug.h
··· 36 36 return bug->flags & BUGFLAG_WARNING; 37 37 } 38 38 39 + void bug_get_file_line(struct bug_entry *bug, const char **file, 40 + unsigned int *line); 41 + 39 42 struct bug_entry *find_bug(unsigned long bugaddr); 40 43 41 44 enum bug_trap_type report_bug(unsigned long bug_addr, struct pt_regs *regs);
+17 -10
lib/bug.c
··· 127 127 } 128 128 #endif 129 129 130 + void bug_get_file_line(struct bug_entry *bug, const char **file, 131 + unsigned int *line) 132 + { 133 + *file = NULL; 134 + *line = 0; 135 + 136 + #ifdef CONFIG_DEBUG_BUGVERBOSE 137 + #ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS 138 + *file = bug->file; 139 + #else 140 + *file = (const char *)bug + bug->file_disp; 141 + #endif 142 + *line = bug->line; 143 + #endif 144 + } 145 + 130 146 struct bug_entry *find_bug(unsigned long bugaddr) 131 147 { 132 148 struct bug_entry *bug; ··· 169 153 170 154 disable_trace_on_warning(); 171 155 172 - file = NULL; 173 - line = 0; 156 + bug_get_file_line(bug, &file, &line); 174 157 175 - #ifdef CONFIG_DEBUG_BUGVERBOSE 176 - #ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS 177 - file = bug->file; 178 - #else 179 - file = (const char *)bug + bug->file_disp; 180 - #endif 181 - line = bug->line; 182 - #endif 183 158 warning = (bug->flags & BUGFLAG_WARNING) != 0; 184 159 once = (bug->flags & BUGFLAG_ONCE) != 0; 185 160 done = (bug->flags & BUGFLAG_DONE) != 0;