]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
serial: max310x: simplify max310x_update_best_err()
authorHugo Villeneuve <hvilleneuve@dimonoff.com>
Fri, 17 Apr 2026 14:53:29 +0000 (10:53 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 11 May 2026 15:20:18 +0000 (17:20 +0200)
besterr was defined as a signed type was to make sure that the first call
to max310x_update_best_err() would always set besterr. Also there is no
need for it to be a long. By changing its type to unsigned int and initial
value to UINT_MAX, max310x_update_best_err() can be simplified and be more
efficient while achieving the same initial result.

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
Link: https://patch.msgid.link/20260417-max310x-2-v1-2-b424e105ecac@dimonoff.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/max310x.c

index 7c1c3696f5684d6dcaf1149e54bfa96c202c7b26..b68a17ebd10b84fa2ecfc521efa454cb248f90b5 100644 (file)
@@ -545,12 +545,12 @@ static int max310x_set_baud(struct uart_port *port, int baud)
        return (16*port->uartclk) / (c*(16*div + frac));
 }
 
-static int max310x_update_best_err(unsigned int f, long *besterr)
+static int max310x_update_best_err(unsigned int f, unsigned int *besterr)
 {
        /* Use baudrate 115200 for calculate error */
-       long err = f % (460800 * 16);
+       unsigned int err = f % (460800 * 16);
 
-       if ((*besterr < 0) || (*besterr > err)) {
+       if (*besterr > err) {
                *besterr = err;
                return 0;
        }
@@ -562,7 +562,7 @@ static s32 max310x_set_ref_clk(struct device *dev, struct max310x_port *s,
                               unsigned int freq, bool xtal)
 {
        unsigned int div, clksrc, pllcfg = 0;
-       long besterr = -1;
+       unsigned int besterr = UINT_MAX;
        unsigned int fdiv, fmul, bestfreq = freq;
 
        /* First, update error without PLL */