[PATCH 1/1] k210: fix k210_pll_calc_config()
Heinrich Schuchardt
heinrich.schuchardt at canonical.com
Sun Oct 16 14:22:57 CEST 2022
On 10/16/22 09:10, Heinrich Schuchardt wrote:
> The k210 driver is selected by sandbox_defconfig.
> Building the sandbox on 32bit systems fails with:
>
> test/dm/k210_pll.c: In function ‘dm_test_k210_pll_calc_config’:
> include/linux/bitops.h:11:38: warning:
> left shift count >= width of type [-Wshift-count-overflow]
> 11 | #define BIT(nr) (1UL << (nr))
> | ^~
> test/dm/k210_pll.c:36:54: note: in expansion of macro ‘BIT’
> 36 | error = abs((error - BIT(32))) >> 16;
> | ^~~
>
> Use the BIT_ULL() macro to create a u64 value.
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
> ---
> drivers/clk/clk_k210.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/clk/clk_k210.c b/drivers/clk/clk_k210.c
> index 1961efaa5e..89195bdda6 100644
> --- a/drivers/clk/clk_k210.c
> +++ b/drivers/clk/clk_k210.c
> @@ -846,7 +846,7 @@ again:
>
> error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od);
> /* The lower 16 bits are spurious */
> - error = abs((error - BIT(32))) >> 16;
> + error = abs((error - BIT_ULL(32))) >> 16;
To get correct results on 32bit systems we must use abs64() instead of
abs(). There is also a unit test to fix.
See review comments in
https://lists.denx.de/pipermail/u-boot/2022-October/497373.html
Best regards
Heinrich
>
> if (error < best_error) {
> best->r = r;
More information about the U-Boot
mailing list