diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2018-10-05 13:39:49 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2018-10-05 13:41:06 +0200 |
commit | b38887ad22e2e28c15b4e248dac72f6eaff8cb13 (patch) | |
tree | e8e6646f8681e5dbe40a0befd7866f5dd272eca7 /cpukit/dev | |
parent | spthreadlife01: A task exit must not return (diff) | |
download | rtems-b38887ad22e2e28c15b4e248dac72f6eaff8cb13.tar.bz2 |
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.
Diffstat (limited to '')
-rw-r--r-- | cpukit/dev/serial/sc16is752.c | 21 |
1 files changed, 13 insertions, 8 deletions
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); |