[rtems commit] dev/sc16is752: Deal with a baud of zero
Sebastian Huber
sebh at rtems.org
Fri Oct 5 11:41:26 UTC 2018
Module: rtems
Branch: master
Commit: b38887ad22e2e28c15b4e248dac72f6eaff8cb13
Changeset: http://git.rtems.org/rtems/commit/?id=b38887ad22e2e28c15b4e248dac72f6eaff8cb13
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Fri Oct 5 13:39:49 2018 +0200
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(-)
diff --git a/cpukit/dev/serial/sc16is752.c b/cpukit/dev/serial/sc16is752.c
index 0dcf217..068a2d3 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);
More information about the vc
mailing list