Skip to content

Commit

Permalink
Merge pull request #327 from sifive/fix-abs-truncation
Browse files Browse the repository at this point in the history
Fix integer truncation on abs() call
  • Loading branch information
nategraff-sifive authored Aug 25, 2020
2 parents 8dc0978 + 771ad8d commit f30b32a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/drivers/sifive_fe310-g000_pll.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f30b32a

Please sign in to comment.