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

serial: arc_uart: simplify flags handling in arc_serial_rx_chars()

* move the declaration of flg (with the initializer) to the loop, so
there is no need to reset it to TTY_NORMAL by an 'else' branch.
* use TTY_NORMAL as initializer above, not a magic zero constant
* remove the outer 'if' from this construct:
if (S & (A | B)) {
if (S & A)
X;
if (S & B)
Y;
}
* drop unlikely() as I doubt it has any benefits here. If it does,
provide numbers.

All four make the code easier to read.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: Vineet Gupta <vgupta@kernel.org>
Acked-by: Vineet Gupta <vgupta@kernel.org>
Link: https://lore.kernel.org/r/20230712081811.29004-9-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jiri Slaby and committed by
Greg Kroah-Hartman
29ec63ef 1225541c

+12 -15
+12 -15
drivers/tty/serial/arc_uart.c
··· 195 195 196 196 static void arc_serial_rx_chars(struct uart_port *port, unsigned int status) 197 197 { 198 - unsigned int ch, flg = 0; 199 - 200 198 /* 201 199 * UART has 4 deep RX-FIFO. Driver's recongnition of this fact 202 200 * is very subtle. Here's how ... ··· 205 207 * controller, which is indeed the Rx-FIFO. 206 208 */ 207 209 do { 210 + unsigned int ch, flg = TTY_NORMAL; 211 + 208 212 /* 209 213 * This could be an Rx Intr for err (no data), 210 214 * so check err and clear that Intr first 211 215 */ 212 - if (unlikely(status & (RXOERR | RXFERR))) { 213 - if (status & RXOERR) { 214 - port->icount.overrun++; 215 - flg = TTY_OVERRUN; 216 - UART_CLR_STATUS(port, RXOERR); 217 - } 216 + if (status & RXOERR) { 217 + port->icount.overrun++; 218 + flg = TTY_OVERRUN; 219 + UART_CLR_STATUS(port, RXOERR); 220 + } 218 221 219 - if (status & RXFERR) { 220 - port->icount.frame++; 221 - flg = TTY_FRAME; 222 - UART_CLR_STATUS(port, RXFERR); 223 - } 224 - } else 225 - flg = TTY_NORMAL; 222 + if (status & RXFERR) { 223 + port->icount.frame++; 224 + flg = TTY_FRAME; 225 + UART_CLR_STATUS(port, RXFERR); 226 + } 226 227 227 228 if (status & RXEMPTY) 228 229 continue;