aw_clk_nm: fix incorrect use of abs()
abs() takes a (signed) int as input. Instead, it was used with unsigned 64-bit integers. So, add and use a new helper function to calculate a difference between two uint64_t-s. Reviewed by: manu MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D26307
This commit is contained in:
parent
04bd07fd15
commit
c3a7328be8
@ -153,7 +153,8 @@ aw_clk_nm_find_best(struct aw_clk_nm_sc *sc, uint64_t fparent, uint64_t *fout,
|
||||
for (m = min_m; m <= max_m; ) {
|
||||
for (n = min_n; n <= max_n; ) {
|
||||
cur = fparent / n / m;
|
||||
if (abs(*fout - cur) < abs(*fout - best)) {
|
||||
if (clk_freq_diff(*fout, cur) <
|
||||
clk_freq_diff(*fout, best)) {
|
||||
best = cur;
|
||||
*factor_n = n;
|
||||
*factor_m = m;
|
||||
@ -196,7 +197,8 @@ aw_clk_nm_set_freq(struct clknode *clk, uint64_t fparent, uint64_t *fout,
|
||||
clknode_get_freq(p_clk, &fparent);
|
||||
|
||||
cur = aw_clk_nm_find_best(sc, fparent, fout, &n, &m);
|
||||
if (abs((*fout - cur)) < abs((*fout - best))) {
|
||||
if (clk_freq_diff(*fout, cur) <
|
||||
clk_freq_diff(*fout, best)) {
|
||||
best = cur;
|
||||
best_parent = p_idx;
|
||||
best_n = n;
|
||||
|
@ -135,6 +135,12 @@ int clk_get_parent(clk_t clk, clk_t *parent);
|
||||
int clk_set_parent_by_clk(clk_t clk, clk_t parent);
|
||||
const char *clk_get_name(clk_t clk);
|
||||
|
||||
static inline uint64_t
|
||||
clk_freq_diff(uint64_t x, uint64_t y)
|
||||
{
|
||||
return (x >= y ? x - y : y - x);
|
||||
}
|
||||
|
||||
#ifdef FDT
|
||||
int clk_set_assigned(device_t dev, phandle_t node);
|
||||
int clk_get_by_ofw_index(device_t dev, phandle_t node, int idx, clk_t *clk);
|
||||
|
Loading…
x
Reference in New Issue
Block a user