Date: Mon, 7 Sep 2020 06:27:18 +0000 (UTC) From: Andriy Gapon <avg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r365395 - in head/sys: arm/allwinner/clkng dev/extres/clk Message-ID: <202009070627.0876RISS033534@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: avg Date: Mon Sep 7 06:27:18 2020 New Revision: 365395 URL: https://svnweb.freebsd.org/changeset/base/365395 Log: 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 Modified: head/sys/arm/allwinner/clkng/aw_clk_nm.c head/sys/dev/extres/clk/clk.h Modified: head/sys/arm/allwinner/clkng/aw_clk_nm.c ============================================================================== --- head/sys/arm/allwinner/clkng/aw_clk_nm.c Mon Sep 7 06:22:30 2020 (r365394) +++ head/sys/arm/allwinner/clkng/aw_clk_nm.c Mon Sep 7 06:27:18 2020 (r365395) @@ -153,7 +153,8 @@ aw_clk_nm_find_best(struct aw_clk_nm_sc *sc, uint64_t 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 fpare 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; Modified: head/sys/dev/extres/clk/clk.h ============================================================================== --- head/sys/dev/extres/clk/clk.h Mon Sep 7 06:22:30 2020 (r365394) +++ head/sys/dev/extres/clk/clk.h Mon Sep 7 06:27:18 2020 (r365395) @@ -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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202009070627.0876RISS033534>