Skip to content

Commit 5c47b7f

Browse files
author
Peter Zijlstra
committed
bug: Add BUG_FORMAT_ARGS infrastructure
Add BUG_FORMAT_ARGS; when an architecture is able to provide a va_list given pt_regs, use this to print format arguments. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://patch.msgid.link/20251110115757.457339417@infradead.org
1 parent 30b8256 commit 5c47b7f

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

include/asm-generic/bug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define BUGFLAG_ONCE (1 << 1)
1414
#define BUGFLAG_DONE (1 << 2)
1515
#define BUGFLAG_NO_CUT_HERE (1 << 3) /* CUT_HERE already sent */
16+
#define BUGFLAG_ARGS (1 << 4)
1617
#define BUGFLAG_TAINT(taint) ((taint) << 8)
1718
#define BUG_GET_TAINT(bug) ((bug)->flags >> 8)
1819
#endif

lib/bug.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,23 @@ struct bug_entry *find_bug(unsigned long bugaddr)
163163
return module_find_bug(bugaddr);
164164
}
165165

166-
static void __warn_printf(const char *fmt)
166+
static void __warn_printf(const char *fmt, struct pt_regs *regs)
167167
{
168168
if (!fmt)
169169
return;
170170

171+
#ifdef HAVE_ARCH_BUG_FORMAT_ARGS
172+
if (regs) {
173+
struct arch_va_list _args;
174+
va_list *args = __warn_args(&_args, regs);
175+
176+
if (args) {
177+
vprintk(fmt, *args);
178+
return;
179+
}
180+
}
181+
#endif
182+
171183
printk("%s", fmt);
172184
}
173185

@@ -193,6 +205,7 @@ static enum bug_trap_type __report_bug(unsigned long bugaddr, struct pt_regs *re
193205
once = bug->flags & BUGFLAG_ONCE;
194206
done = bug->flags & BUGFLAG_DONE;
195207
no_cut = bug->flags & BUGFLAG_NO_CUT_HERE;
208+
has_args = bug->flags & BUGFLAG_ARGS;
196209

197210
if (warning && once) {
198211
if (done)
@@ -212,7 +225,7 @@ static enum bug_trap_type __report_bug(unsigned long bugaddr, struct pt_regs *re
212225
*/
213226
if (!no_cut) {
214227
printk(KERN_DEFAULT CUT_HERE);
215-
__warn_printf(fmt);
228+
__warn_printf(fmt, has_args ? regs : NULL);
216229
}
217230

218231
if (warning) {

0 commit comments

Comments
 (0)