serial: mvebu-uart: fix calculation of clock divisor
authorPali Rohár <pali@kernel.org>
Thu, 24 Jun 2021 22:49:00 +0000 (00:49 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 14 Jul 2021 14:55:45 +0000 (16:55 +0200)
commit 9078204ca5c33ba20443a8623a41a68a9995a70d upstream.

The clock divisor should be rounded to the closest value.

Signed-off-by: Pali Rohár <pali@kernel.org>
Fixes: 68a0db1d7da2 ("serial: mvebu-uart: add function to change baudrate")
Cc: stable@vger.kernel.org # 0e4cf69ede87 ("serial: mvebu-uart: clarify the baud rate derivation")
Link: https://lore.kernel.org/r/20210624224909.6350-2-pali@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/mvebu-uart.c

index 51b0ecabf2ec963ffefcd33999b08f1d9830931e..908a4ac6b5a7accf38f3b3fd1d96ed7fbac68365 100644 (file)
@@ -463,7 +463,7 @@ static int mvebu_uart_baud_rate_set(struct uart_port *port, unsigned int baud)
         * makes use of D to configure the desired baudrate.
         */
        m_divisor = OSAMP_DEFAULT_DIVISOR;
-       d_divisor = DIV_ROUND_UP(port->uartclk, baud * m_divisor);
+       d_divisor = DIV_ROUND_CLOSEST(port->uartclk, baud * m_divisor);
 
        brdv = readl(port->membase + UART_BRDV);
        brdv &= ~BRDV_BAUD_MASK;