drivers: console: uart_console: avoid infinite loop in isr

Previously, the `uart_console_isr()` routine assumed that the
return value of several uart API functions would only ever
return the equivalent of a boolean value. In fact, an integer
is returned on occasion, and that integer can take on many
values.

Since unary operations would either go to "true" or "false"
and since any non-zero integer evaluates to "true", even a
return value of something like `-ENODEV` would evalueate
to true.

Explicitly compare against the integer-equivalent value of
the expected boolean output.

With this, in the case of errors, negative return values do
not evaluate to "true", and the infinite loop is avoied.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
This commit is contained in:
Christopher Friedt 2023-09-22 15:20:28 -04:00 committed by Carles Cufí
commit a05c88daa5

View file

@ -446,13 +446,18 @@ static void uart_console_isr(const struct device *unused, void *user_data)
ARG_UNUSED(user_data);
static uint8_t last_char = '\0';
while (uart_irq_update(uart_console_dev) &&
uart_irq_is_pending(uart_console_dev)) {
while (uart_irq_update(uart_console_dev) > 0 &&
uart_irq_is_pending(uart_console_dev) > 0) {
static struct console_input *cmd;
uint8_t byte;
int rx;
if (!uart_irq_rx_ready(uart_console_dev)) {
rx = uart_irq_rx_ready(uart_console_dev);
if (rx < 0) {
return;
}
if (rx == 0) {
continue;
}
@ -561,7 +566,7 @@ static void console_input_init(void)
uart_irq_callback_set(uart_console_dev, uart_console_isr);
/* Drain the fifo */
while (uart_irq_rx_ready(uart_console_dev)) {
while (uart_irq_rx_ready(uart_console_dev) > 0) {
uart_fifo_read(uart_console_dev, &c, 1);
}