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

powerpc/xmon: Fallback to printk() in xmon_printf() if udbg is not setup

It is possible to configure a kernel which has xmon enabled, but has no
udbg backend to provide IO. This can make xmon rather confusing, as it
produces no output, blocks for two seconds, and then returns.

As a last resort we can instead try to printk(), which may deadlock or
otherwise crash, but tries quite hard not to.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

authored by

Michael Ellerman and committed by
Benjamin Herrenschmidt
b2bb65f6 0104cd68

+8 -2
+8 -2
arch/powerpc/xmon/nonstdio.c
··· 111 111 void xmon_printf(const char *format, ...) 112 112 { 113 113 va_list args; 114 - int n; 115 114 static char xmon_outbuf[1024]; 115 + int rc, n; 116 116 117 117 va_start(args, format); 118 118 n = vsnprintf(xmon_outbuf, sizeof(xmon_outbuf), format, args); 119 119 va_end(args); 120 - xmon_write(xmon_outbuf, n); 120 + 121 + rc = xmon_write(xmon_outbuf, n); 122 + 123 + if (n && rc == 0) { 124 + /* No udbg hooks, fallback to printk() - dangerous */ 125 + printk(xmon_outbuf); 126 + } 121 127 } 122 128 123 129 void xmon_puts(const char *str)