Skip to content

Commit 5b2ebce

Browse files
JoePerchesgregkh
authored andcommitted
dynamic_debug: Remove uses of KERN_CONT in dynamic_emit_prefix
Multiple printks with KERN_CONT can be interleaved by other printks. Reduce the likelihood of that interleaving by consolidating multiple calls to printk. Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: Jason Baron <jbaron@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 6c2140e commit 5b2ebce

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

‎lib/dynamic_debug.c‎

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -430,23 +430,35 @@ static int ddebug_exec_query(char *query_string)
430430

431431
static int dynamic_emit_prefix(const struct _ddebug *descriptor)
432432
{
433-
int res;
433+
char tid[sizeof(int) + sizeof(int)/2 + 4];
434+
char lineno[sizeof(int) + sizeof(int)/2];
434435

435-
res = printk(KERN_DEBUG);
436436
if (descriptor->flags & _DPRINTK_FLAGS_INCL_TID) {
437437
if (in_interrupt())
438-
res += printk(KERN_CONT "<intr> ");
438+
snprintf(tid, sizeof(tid), "%s", "<intr> ");
439439
else
440-
res += printk(KERN_CONT "[%d] ", task_pid_vnr(current));
440+
snprintf(tid, sizeof(tid), "[%d] ",
441+
task_pid_vnr(current));
442+
} else {
443+
tid[0] = 0;
441444
}
442-
if (descriptor->flags & _DPRINTK_FLAGS_INCL_MODNAME)
443-
res += printk(KERN_CONT "%s:", descriptor->modname);
444-
if (descriptor->flags & _DPRINTK_FLAGS_INCL_FUNCNAME)
445-
res += printk(KERN_CONT "%s:", descriptor->function);
446-
if (descriptor->flags & _DPRINTK_FLAGS_INCL_LINENO)
447-
res += printk(KERN_CONT "%d ", descriptor->lineno);
448445

449-
return res;
446+
if (descriptor->flags & _DPRINTK_FLAGS_INCL_LINENO)
447+
snprintf(lineno, sizeof(lineno), "%d", descriptor->lineno);
448+
else
449+
lineno[0] = 0;
450+
451+
return printk(KERN_DEBUG "%s%s%s%s%s%s",
452+
tid,
453+
(descriptor->flags & _DPRINTK_FLAGS_INCL_MODNAME) ?
454+
descriptor->modname : "",
455+
(descriptor->flags & _DPRINTK_FLAGS_INCL_MODNAME) ?
456+
":" : "",
457+
(descriptor->flags & _DPRINTK_FLAGS_INCL_FUNCNAME) ?
458+
descriptor->function : "",
459+
(descriptor->flags & _DPRINTK_FLAGS_INCL_FUNCNAME) ?
460+
":" : "",
461+
lineno);
450462
}
451463

452464
int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...)

0 commit comments

Comments
 (0)