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 <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>
This commit is contained in:
Hugo Villeneuve 2026-04-17 10:53:29 -04:00 committed by Greg Kroah-Hartman
parent 0dcaf1c6b2
commit db3c618405

View 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 */