diff options
author | marcel <marcel@FreeBSD.org> | 2004-11-15 00:00:24 +0000 |
---|---|---|
committer | marcel <marcel@FreeBSD.org> | 2004-11-15 00:00:24 +0000 |
commit | ec1c3ebc3d9cfa9eb8961cf1117217702bb8d271 (patch) | |
tree | e372164c8fced9ab7fe3dc7ed444eda849892b0c | |
parent | 48c39479f71478c0b7666a5e4a3bc4eb8154d911 (diff) | |
download | FreeBSD-src-ec1c3ebc3d9cfa9eb8961cf1117217702bb8d271.zip FreeBSD-src-ec1c3ebc3d9cfa9eb8961cf1117217702bb8d271.tar.gz |
Be slightly more paranoid about using the divisor in a division and
the calculated baudrate. Neither should be 0.
-rw-r--r-- | sys/dev/uart/uart_dev_ns8250.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/sys/dev/uart/uart_dev_ns8250.c b/sys/dev/uart/uart_dev_ns8250.c index 975ed4d..5869d33 100644 --- a/sys/dev/uart/uart_dev_ns8250.c +++ b/sys/dev/uart/uart_dev_ns8250.c @@ -468,7 +468,7 @@ static int ns8250_bus_ioctl(struct uart_softc *sc, int request, intptr_t data) { struct uart_bas *bas; - int divisor, error; + int baudrate, divisor, error; uint8_t efr, lcr; bas = &sc->sc_bas; @@ -522,7 +522,11 @@ ns8250_bus_ioctl(struct uart_softc *sc, int request, intptr_t data) uart_barrier(bas); uart_setreg(bas, REG_LCR, lcr); uart_barrier(bas); - *(int*)data = bas->rclk / divisor / 16; + baudrate = (divisor > 0) ? bas->rclk / divisor / 16 : 0; + if (baudrate > 0) + *(int*)data = baudrate; + else + error = ENXIO; break; default: error = EINVAL; |