From: Hugo Villeneuve Date: Fri, 17 Apr 2026 14:53:29 +0000 (-0400) Subject: serial: max310x: simplify max310x_update_best_err() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db3c618405d2a4ac870915b8438ff17be93b5f16;p=thirdparty%2Fkernel%2Fstable.git serial: max310x: simplify max310x_update_best_err() 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 Link: https://patch.msgid.link/20260417-max310x-2-v1-2-b424e105ecac@dimonoff.com Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index 7c1c3696f568..b68a17ebd10b 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -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 */