Skip to content

Commit 00c7ded

Browse files
nathanchancebebarino
authored andcommitted
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: 48cf7e0 ("clk: sophgo: Add SG2042 clock driver") Signed-off-by: Nathan Chancellor <[email protected]> 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 <[email protected]>
1 parent 1f7a04a commit 00c7ded

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

drivers/clk/sophgo/clk-sg2042-pll.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static inline void sg2042_pll_ctrl_decode(unsigned int reg_value,
103103
ctrl->postdiv2 = FIELD_GET(PLLCTRL_POSTDIV2_MASK, reg_value);
104104
}
105105

106-
static inline int sg2042_pll_enable(struct sg2042_pll_clock *pll, bool en)
106+
static inline void sg2042_pll_enable(struct sg2042_pll_clock *pll, bool en)
107107
{
108108
u32 value;
109109

@@ -132,8 +132,6 @@ static inline int sg2042_pll_enable(struct sg2042_pll_clock *pll, bool en)
132132
value = readl(pll->base + R_PLL_CLKEN_CONTROL);
133133
writel(value & (~(1 << pll->shift_enable)), pll->base + R_PLL_CLKEN_CONTROL);
134134
}
135-
136-
return 0;
137135
}
138136

139137
/**
@@ -393,24 +391,23 @@ static int sg2042_clk_pll_set_rate(struct clk_hw *hw,
393391
int ret;
394392

395393
spin_lock_irqsave(pll->lock, flags);
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-
}
394+
395+
sg2042_pll_enable(pll, 0);
396+
400397
ret = sg2042_get_pll_ctl_setting(&pctrl_table, rate, parent_rate);
401398
if (ret) {
402399
pr_warn("%s: Can't find a proper pll setting\n", pll->hw.init->name);
403-
goto out2;
400+
goto out;
404401
}
405402

406403
value = sg2042_pll_ctrl_encode(&pctrl_table);
407404

408405
/* write the value to top register */
409406
writel(value, pll->base + pll->offset_ctrl);
410407

411-
out2:
412-
sg2042_pll_enable(pll, 1);
413408
out:
409+
sg2042_pll_enable(pll, 1);
410+
414411
spin_unlock_irqrestore(pll->lock, flags);
415412

416413
pr_debug("--> %s: pll_set_rate: val = 0x%x\n",

0 commit comments

Comments
 (0)