powerpc: Fix bad NULL pointer check in udbg_uart_getc_poll()
authorAnton Blanchard <anton@samba.org>
Mon, 10 Nov 2014 22:12:28 +0000 (09:12 +1100)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 12 Nov 2014 02:47:20 +0000 (13:47 +1100)
We have some code in udbg_uart_getc_poll() that tries to protect
against a NULL udbg_uart_in, but gets it all wrong.

Found with the LLVM static analyzer (scan-build).

Fixes: 309257484cc1 ("powerpc: Cleanup udbg_16550 and add support for LPC PIO-only UARTs")
Signed-off-by: Anton Blanchard <anton@samba.org>
[mpe: Add some newlines for readability while we're here]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/kernel/udbg_16550.c

index 6e7c4923b5ea1bb24427bc47360576900bc44fe8..411116c38da44df71c4013a5688c5f775baa2b0e 100644 (file)
@@ -69,8 +69,12 @@ static void udbg_uart_putc(char c)
 
 static int udbg_uart_getc_poll(void)
 {
-       if (!udbg_uart_in || !(udbg_uart_in(UART_LSR) & LSR_DR))
+       if (!udbg_uart_in)
+               return -1;
+
+       if (!(udbg_uart_in(UART_LSR) & LSR_DR))
                return udbg_uart_in(UART_RBR);
+
        return -1;
 }