From b38887ad22e2e28c15b4e248dac72f6eaff8cb13 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 5 Oct 2018 13:39:49 +0200 Subject: dev/sc16is752: Deal with a baud of zero Avoid division by zero and instead disable rx/tx in case of a zero baud value. Problem identified by Coverity Scan. --- cpukit/dev/serial/sc16is752.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'cpukit/dev') diff --git a/cpukit/dev/serial/sc16is752.c b/cpukit/dev/serial/sc16is752.c index 0dcf21765a..068a2d3817 100644 --- a/cpukit/dev/serial/sc16is752.c +++ b/cpukit/dev/serial/sc16is752.c @@ -143,21 +143,26 @@ static bool sc16is752_set_attributes( ) { sc16is752_context *ctx = (sc16is752_context *)base; - bool baud_successful; rtems_termios_baud_t baud; ctx->lcr = 0; baud = rtems_termios_baud_to_number(term->c_ospeed); - baud_successful = set_baud(ctx, baud); - if (!baud_successful){ - return false; - } - if ((term->c_cflag & CREAD) == 0){ - ctx->efcr |= SC16IS752_EFCR_RX_DISABLE; + if (baud > 0) { + if (!set_baud(ctx, baud)){ + return false; + } + + ctx->efcr &= ~SC16IS752_EFCR_TX_DISABLE; + + if ((term->c_cflag & CREAD) == 0){ + ctx->efcr |= SC16IS752_EFCR_RX_DISABLE; + } else { + ctx->efcr &= ~SC16IS752_EFCR_RX_DISABLE; + } } else { - ctx->efcr &= ~SC16IS752_EFCR_RX_DISABLE; + ctx->efcr |= SC16IS752_EFCR_RX_DISABLE | SC16IS752_EFCR_TX_DISABLE; } write_reg(ctx, SC16IS752_EFCR, &ctx->efcr, 1); -- cgit v1.2.3