summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2018-05-08 14:15:02 -0700
committerSascha Hauer <s.hauer@pengutronix.de>2018-08-13 09:13:43 +0200
commit958f0311136b3e47a1ce3093663f74c4ee139558 (patch)
tree148000c4f2f16563bd696d92eec88ee09124da0f /drivers
parent1df07fbcdfce7852cf97a0397b20b586248e1226 (diff)
downloadbarebox-958f0311136b3e47a1ce3093663f74c4ee139558.tar.gz
barebox-958f0311136b3e47a1ce3093663f74c4ee139558.tar.xz
serial: lpuart: Avoid division by zero when requested baudrate is
With serdev device support added there's now a corner case where: 1. There is a DT node for a serdev device on one of the UARTs 2. There is no driver that binds against serdev device's compatibility string with 1 and 2 being true it is possible to end up in a situation where a particualr UART has not been initalized to any baudrate when clock_notifier_call_chain() gets called. This effectively translates to set_baudrate(uart, 0); which for LPUART driver result in a division by zero. To avoid this problem, convert lpuart_serial_setbaudrate() to treat zero baudrate as a request to disable the UART. While we are at it add a BUG_ON() to lpuart_setbrg() to simplify finding any future bugs. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/serial/serial_lpuart.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/drivers/serial/serial_lpuart.c b/drivers/serial/serial_lpuart.c
index f28035a326..246fc3d3af 100644
--- a/drivers/serial/serial_lpuart.c
+++ b/drivers/serial/serial_lpuart.c
@@ -68,11 +68,14 @@ static int lpuart_serial_setbaudrate(struct console_device *cdev,
lpuart_enable(lpuart, false);
- lpuart_setbrg(lpuart->base,
- clk_get_rate(lpuart->clk),
- baudrate);
-
- lpuart_enable(lpuart, true);
+ /*
+ * We treat baudrate of 0 as a request to disable UART
+ */
+ if (baudrate) {
+ lpuart_setbrg(lpuart->base, clk_get_rate(lpuart->clk),
+ baudrate);
+ lpuart_enable(lpuart, true);
+ }
lpuart->baudrate = baudrate;