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: <CAJF2gTQckdn=uDfeLKu7wceOq7LT1KGJUT0vARMr9zUy3xc4xw@mail.gmail.com>
Date:   Wed, 13 Dec 2023 09:26:01 +0800
From:   Guo Ren <guoren@...nel.org>
To:     Arnd Bergmann <arnd@...nel.org>
Cc:     Pavel Machek <pavel@....cz>, Lee Jones <lee@...nel.org>,
        Chen-Yu Tsai <wens@...e.org>,
        Jernej Skrabec <jernej.skrabec@...il.com>,
        Samuel Holland <samuel@...lland.org>,
        Nathan Chancellor <nathan@...nel.org>,
        Palmer Dabbelt <palmer@...osinc.com>,
        Arnd Bergmann <arnd@...db.de>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        Bill Wendling <morbo@...gle.com>,
        Justin Stitt <justinstitt@...gle.com>,
        linux-leds@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
        linux-sunxi@...ts.linux.dev, linux-kernel@...r.kernel.org,
        llvm@...ts.linux.dev
Subject: Re: [PATCH] leds: sun50i-a100: avoid division-by-zero warning

On Wed, Dec 13, 2023 at 5:45 AM Arnd Bergmann <arnd@...nel.org> wrote:
>
> From: Arnd Bergmann <arnd@...db.de>
>
> When CONFIG_COMMON_CLK is disabled, e.g. on an x86 randconfig compile test,
> clang reports a field overflow from propagating the result of a division by
> zero:
>
> drivers/leds/leds-sun50i-a100.c:309:12: error: call to '__compiletime_assert_265' declared with 'error' attribute: FIELD_PREP: value too large for the field
>         control = FIELD_PREP(LEDC_T01_TIMING_CTRL_REG_T1H, timing->t1h_ns / cycle_ns) |
>
> Avoid the problem by adding an explicit check for the zero value here. Alternatively
> the assertion could be avoided with a Kconfig dependency on COMMON_CLK.
>
> Fixes: 090a25ad9798 ("leds: sun50i-a100: New driver for the A100 LED controller")
> Signed-off-by: Arnd Bergmann <arnd@...db.de>
> ---
>  drivers/leds/leds-sun50i-a100.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/leds/leds-sun50i-a100.c b/drivers/leds/leds-sun50i-a100.c
> index e4a7e692a908..171cefd1ea0d 100644
> --- a/drivers/leds/leds-sun50i-a100.c
> +++ b/drivers/leds/leds-sun50i-a100.c
> @@ -303,9 +303,13 @@ static void sun50i_a100_ledc_set_timing(struct sun50i_a100_ledc *priv)
>  {
>         const struct sun50i_a100_ledc_timing *timing = &priv->timing;
>         unsigned long mod_freq = clk_get_rate(priv->mod_clk);
> -       u32 cycle_ns = NSEC_PER_SEC / mod_freq;
> +       u32 cycle_ns;
>         u32 control;
>
> +       if (!mod_freq)
> +               return;
> +
Shall we need err_disable_bus_clk?

+ static int sun50i_a100_ledc_set_timing(struct sun50i_a100_ledc *priv)
- static void sun50i_a100_ledc_set_timing(struct sun50i_a100_ledc *priv)
 {
         const struct sun50i_a100_ledc_timing *timing = &priv->timing;
         unsigned long mod_freq = clk_get_rate(priv->mod_clk);
 -       u32 cycle_ns = NSEC_PER_SEC / mod_freq;
 +       u32 cycle_ns;
         u32 control;

+       if (!mod_freq)
+               return -EINVAL;

 +       cycle_ns = NSEC_PER_SEC / mod_freq;
         control = FIELD_PREP(LEDC_T01_TIMING_CTRL_REG_T1H,
timing->t1h_ns / cycle_ns) |
                   FIELD_PREP(LEDC_T01_TIMING_CTRL_REG_T1L,
timing->t1l_ns / cycle_ns) |
                   FIELD_PREP(LEDC_T01_TIMING_CTRL_REG_T0H,
timing->t0h_ns / cycle_ns) |
...
       return 0;

----------

+ ret = sun50i_a100_ledc_set_timing(priv);
+ if (ret)
+         goto err_disable_bus_clk;



> --
> 2.39.2
>


-- 
Best Regards
 Guo Ren

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ