lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMuHMdX0xP5Gugo7uF5Wqk9_ny6-4fOWYRm41KicOo26kC6m+g@mail.gmail.com>
Date:   Mon, 24 Jul 2023 12:04:19 +0200
From:   Geert Uytterhoeven <geert@...ux-m68k.org>
To:     wuyonggang001@...suo.com
Cc:     mturquette@...libre.com, sboyd@...nel.org,
        linux-clk@...r.kernel.org, linux-kernel@...r.kernel.org,
        Serge Semin <fancer.lancer@...il.com>
Subject: Re: [PATCH] clk: baikal-t1: Using div64_ Ul replaces do_ Div() function

Hi Yonggang,

CC Serge

On Wed, Jun 14, 2023 at 8:07 AM <wuyonggang001@...suo.com> wrote:
> Fix the following coccicheck warning:
>
> drivers/clk/baikal-t1/ccu-pll.c:81:1-7: WARNING: do_div() does a
> 64-by-32 division, please consider using div64_ul instead.
>
> Signed-off-by: Yonggang Wu <wuyonggang001@...suo.com>

Thanks for your patch, which is now commit b93d1331ea266dea
("clk: baikal-t1: Using div64_ Ul replaces do_ Div() function")
in clk/clk-next.

> b/drivers/clk/baikal-t1/ccu-pll.c
> index 13ef28001439..d41735c6956a 100644
> --- a/drivers/clk/baikal-t1/ccu-pll.c
> +++ b/drivers/clk/baikal-t1/ccu-pll.c
> @@ -66,7 +66,7 @@ static inline unsigned long
> ccu_pll_lock_delay_us(unsigned long ref_clk,
>   {
>       u64 us = 500ULL * nr * USEC_PER_SEC;
>
> -    do_div(us, ref_clk);
> +    div64_ul(us, ref_clk);

The above is not equivalent:
  - do_div() returned the quotient as an output parameter in us,
  - div64_ul() returns the quotient using the return value.

Have you tested your patch?

>
>       return us;

So this should become:

    return div64_ul(500ULL * nr * USEC_PER_SEC, ref_clk);

>   }
> @@ -78,9 +78,9 @@ static inline unsigned long ccu_pll_calc_freq(unsigned
> long ref_clk,
>   {
>       u64 tmp = ref_clk;
>
> -    do_div(tmp, nr);
> +    div64_ul(tmp, nr);
>       tmp *= nf;
> -    do_div(tmp, od);
> +    div64_ul(tmp, od);
>
>       return tmp;

Likewise.
But as ref_clk is unsigned long, there is no need to use div64_ul()
for the first division, and this can be simplified to:

    u64 tmp = (u64)(ref_clk / nr) * nf;
    return div64_ul(tmp, od);

To avoid loss of precision, it might be better to reverse the order
of the division and multiplication:

    u64 tmp = (u64)ref_clk * nf / nr;

But doing that requires intimate knowledge about the range of nf to
avoid overflow, so I leave that to Serge.

>   }

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@...ux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ