diff mbox series

powerpc/xmon: Fix whitespace handling in getstring()

Message ID 20200217014741.27984-1-oohall@gmail.com
State Not Applicable
Headers show
Series powerpc/xmon: Fix whitespace handling in getstring() | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch warning Failed to apply on branch master (53944d45087bd78bf7f9494a54e464c74322a83a)
snowpatch_ozlabs/apply_patch fail Failed to apply to any branch

Commit Message

Oliver O'Halloran Feb. 17, 2020, 1:47 a.m. UTC
The ls (lookup symbol) and zr (reboot) commands use xmon's getstring()
helper to read a string argument from the xmon prompt. This function skips
over leading whitespace, but doesn't check if the first "non-whitespace"
character is a newline which causes some odd behaviour (<enter> indicates
a the enter key was pressed):

	0:mon> ls printk<enter>
	printk: c0000000001680c4

	0:mon> ls<enter>
	printk<enter>
	Symbol '
	printk' not found.
	0:mon>

With commit 2d9b332d99b ("powerpc/xmon: Allow passing an argument
to ppc_md.restart()") we have a similar problem with the zr command.
Previously zr took no arguments so "zr<enter> would trigger a reboot.
With that patch applied a second newline needs to be sent in order for
the reboot to occur. Fix this by checking if the leading whitespace
ended on a newline:

	0:mon> ls<enter>
	Symbol '' not found.

Fixes: 2d9b332d99b ("powerpc/xmon: Allow passing an argument to ppc_md.restart()")
Reported-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 arch/powerpc/xmon/xmon.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Oliver O'Halloran Feb. 17, 2020, 4:06 a.m. UTC | #1
On Mon, Feb 17, 2020 at 12:47 PM Oliver O'Halloran <oohall@gmail.com> wrote:
>
> The ls (lookup symbol) and zr (reboot) commands use xmon's getstring()
> helper to read a string argument from the xmon prompt. This function skips
> over leading whitespace, but doesn't check if the first "non-whitespace"
> character is a newline which causes some odd behaviour (<enter> indicates
> a the enter key was pressed):
>
>         0:mon> ls printk<enter>
>         printk: c0000000001680c4
>
>         0:mon> ls<enter>
>         printk<enter>
>         Symbol '
>         printk' not found.
>         0:mon>
>
> With commit 2d9b332d99b ("powerpc/xmon: Allow passing an argument
> to ppc_md.restart()") we have a similar problem with the zr command.
> Previously zr took no arguments so "zr<enter> would trigger a reboot.
> With that patch applied a second newline needs to be sent in order for
> the reboot to occur. Fix this by checking if the leading whitespace
> ended on a newline:
>
>         0:mon> ls<enter>
>         Symbol '' not found.
>
> Fixes: 2d9b332d99b ("powerpc/xmon: Allow passing an argument to ppc_md.restart()")
> Reported-by: Michael Ellerman <mpe@ellerman.id.au>
> Signed-off-by: Oliver O'Halloran <oohall@gmail.com>

Sending it to the right list might help, go me.
diff mbox series

Patch

diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index e8c84d26..0ec9640 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -3435,6 +3435,11 @@  getstring(char *s, int size)
 	int c;
 
 	c = skipbl();
+	if (c == '\n') {
+		*s = 0;
+		return;
+	}
+
 	do {
 		if( size > 1 ){
 			*s++ = c;