Commit Graph

5 Commits

Author SHA1 Message Date
Pei Xiao
2f80dfab86
clk: sophgo: Use div64* for 64-by-32 division to simplify
Fixes Coccinelle/coccicheck warnings reported by do_div.cocci.

cocci warnings:
    drivers/clk/sophgo/clk-sg2042-pll.c:217:1-7: WARNING:
    do_div() does a 64-by-32 division, please consider using div64_ul
    instead.

    drivers/clk/sophgo/clk-sg2042-pll.c:160:1-7: WARNING:
    do_div() does a 64-by-32 division, please consider using div64_u64
    instead.

replace do_div() with div64_*() which doesn't implicitly cast the divisor.

Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
Link: https://lore.kernel.org/r/tencent_D5D35C992B70843CF70F5533E49717D24906@qq.com
Reviewed-by: Inochi Amaoto <inochiama@gmail.com>
Reviewed-by: Chen Wang <wangchen20@iscas.ac.cn>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2025-06-19 16:53:49 -07:00
Zichen Xie
00f8f70a0e clk: sophgo: avoid integer overflow in sg2042_pll_recalc_rate()
This was found by a static analyzer.
There may be a potential integer overflow issue in
sg2042_pll_recalc_rate(). numerator is defined as u64 while
parent_rate is defined as unsigned long and ctrl_table.fbdiv
is defined as unsigned int. On 32-bit machine, the result of
the calculation will be limited to "u32" without correct casting.
Integer overflow may occur on high-performance systems.

Fixes: 48cf7e0138 ("clk: sophgo: Add SG2042 clock driver")
Signed-off-by: Zichen Xie <zichenxie0106@gmail.com>
Reviewed-by: Chen Wang <unicorn_wang@outlook.com>
Link: https://lore.kernel.org/r/20241023145146.13130-1-zichenxie0106@gmail.com
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2024-10-28 16:47:22 -07:00
Dan Carpenter
5a6a25ea5b clk: sophgo: clk-sg2042-pll: Fix uninitialized variable in debug output
If sg2042_get_pll_ctl_setting() fails then "value" isn't initialized and
it is printed in the debug output.  Initialize it to zero.

Fixes: 48cf7e0138 ("clk: sophgo: Add SG2042 clock driver")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/r/baf0a490-d5ba-4528-90ba-80399684692d@stanley.mountain
Reviewed-by: Chen Wang <unicorn_wang@outlook.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2024-07-18 13:33:15 -07:00
Nathan Chancellor
00c7ded680 clk: sophgo: Avoid -Wsometimes-uninitialized in sg2042_clk_pll_set_rate()
Clang warns (or errors with CONFIG_WERROR=y):

  drivers/clk/sophgo/clk-sg2042-pll.c:396:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
    396 |         if (sg2042_pll_enable(pll, 0)) {
        |             ^~~~~~~~~~~~~~~~~~~~~~~~~
  drivers/clk/sophgo/clk-sg2042-pll.c:418:9: note: uninitialized use occurs here
    418 |         return ret;
        |                ^~~
  drivers/clk/sophgo/clk-sg2042-pll.c:396:2: note: remove the 'if' if its condition is always false
    396 |         if (sg2042_pll_enable(pll, 0)) {
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    397 |                 pr_warn("Can't disable pll(%s), status error\n", pll->hw.init->name);
        |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    398 |                 goto out;
        |                 ~~~~~~~~~
    399 |         }
        |         ~
  drivers/clk/sophgo/clk-sg2042-pll.c:393:9: note: initialize the variable 'ret' to silence this warning
    393 |         int ret;
        |                ^
        |                 = 0
  1 error generated.

sg2042_pll_enable() only ever returns zero, so this situation cannot
happen, but clang does not perform interprocedural analysis, so it
cannot know this to avoid the warning. Make it clearer to the compiler
by making sg2042_pll_enable() void and eliminate the error handling in
sg2042_clk_pll_set_rate(), which clears up the warning, as ret will
always be initialized.

Fixes: 48cf7e0138 ("clk: sophgo: Add SG2042 clock driver")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Link: https://lore.kernel.org/r/20240710-clk-sg2042-fix-sometimes-uninitialized-pll_set_rate-v1-1-538fa82dd539@kernel.org
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2024-07-10 14:16:45 -07:00
Chen Wang
48cf7e0138 clk: sophgo: Add SG2042 clock driver
Add a driver for the SOPHGO SG2042 clocks.

Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
2024-06-14 14:49:40 +08:00