[PATCH 02/10] serial: max310x: simplify max310x_update_best_err()
From: Hugo Villeneuve
Date: Fri Apr 17 2026 - 11:40:16 EST
From: Hugo Villeneuve <hvilleneuve@xxxxxxxxxxxx>
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@xxxxxxxxxxxx>
---
drivers/tty/serial/max310x.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index 7c1c3696f5684d6dcaf1149e54bfa96c202c7b26..b68a17ebd10b84fa2ecfc521efa454cb248f90b5 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 */
--
2.47.3