From 771ad8d9d847a7079e5053bb2aa8347d44e46eb4 Mon Sep 17 00:00:00 2001 From: Nathaniel Graff Date: Tue, 25 Aug 2020 14:20:49 -0700 Subject: [PATCH] Fix integer truncation on abs() call GCC 10 complains about possible integer truncation when passing a long int to abs(). Signed-off-by: Nathaniel Graff --- src/drivers/sifive_fe310-g000_pll.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/drivers/sifive_fe310-g000_pll.c b/src/drivers/sifive_fe310-g000_pll.c index ab482f40..e3e4437d 100644 --- a/src/drivers/sifive_fe310-g000_pll.c +++ b/src/drivers/sifive_fe310-g000_pll.c @@ -260,7 +260,13 @@ static int find_closest_config(long ref_hz, long rate) { i--) { long config_freq = get_pll_config_freq(ref_hz, &(pll_configs[i])); if (config_freq != PLL_CONFIG_NOT_VALID) { - long freq_diff = abs(config_freq - rate); + long freq_diff; + if (config_freq > rate) { + freq_diff = config_freq - rate; + } else { + freq_diff = rate - config_freq; + } + if (freq_diff < closest_diff) { closest_index = i; closest_diff = freq_diff;