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

login
register
mail settings
Submitter Michael Ellerman
Date Oct. 9, 2012, 2:20 p.m.
Message ID <1349792447-15714-20-git-send-email-michael@ellerman.id.au>
Download mbox | patch
Permalink /patch/190333/
State Accepted, archived
Commit b2bb65f680a7b2faa5d6332c02752dca83a49cd6
Delegated to: Benjamin Herrenschmidt
Headers show

Comments

Michael Ellerman - Oct. 9, 2012, 2:20 p.m.
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>
---
 arch/powerpc/xmon/nonstdio.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Patch

diff --git a/arch/powerpc/xmon/nonstdio.c b/arch/powerpc/xmon/nonstdio.c
index 942d0f6..bce3dcf 100644
--- a/arch/powerpc/xmon/nonstdio.c
+++ b/arch/powerpc/xmon/nonstdio.c
@@ -111,13 +111,19 @@  char *xmon_gets(char *str, int nb)
 void xmon_printf(const char *format, ...)
 {
 	va_list args;
-	int n;
 	static char xmon_outbuf[1024];
+	int rc, n;
 
 	va_start(args, format);
 	n = vsnprintf(xmon_outbuf, sizeof(xmon_outbuf), format, args);
 	va_end(args);
-	xmon_write(xmon_outbuf, n);
+
+	rc = xmon_write(xmon_outbuf, n);
+
+	if (n && rc == 0) {
+		/* No udbg hooks, fallback to printk() - dangerous */
+		printk(xmon_outbuf);
+	}
 }
 
 void xmon_puts(const char *str)