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

powerpc: Fix bad NULL pointer check in udbg_uart_getc_poll()

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>

authored by

Anton Blanchard and committed by
Michael Ellerman
cd32e2dc 6609ed14

+5 -1
+5 -1
arch/powerpc/kernel/udbg_16550.c
··· 69 69 70 70 static int udbg_uart_getc_poll(void) 71 71 { 72 - if (!udbg_uart_in || !(udbg_uart_in(UART_LSR) & LSR_DR)) 72 + if (!udbg_uart_in) 73 + return -1; 74 + 75 + if (!(udbg_uart_in(UART_LSR) & LSR_DR)) 73 76 return udbg_uart_in(UART_RBR); 77 + 74 78 return -1; 75 79 } 76 80