Skip to content

Commit 6c9feab

Browse files
Michal Simekbebarino
authored andcommitted
clk: zynqmp: fix compile testing without ZYNQMP_FIRMWARE
When the firmware code is disabled, the incomplete error handling in the clk driver causes compile-time warnings: drivers/clk/zynqmp/pll.c: In function 'zynqmp_pll_recalc_rate': drivers/clk/zynqmp/pll.c:147:29: error: 'fbdiv' is used uninitialized [-Werror=uninitialized] 147 | rate = parent_rate * fbdiv; | ~~~~~~~~~~~~^~~~~~~ In function 'zynqmp_pll_get_mode', inlined from 'zynqmp_pll_recalc_rate' at drivers/clk/zynqmp/pll.c:148:6: drivers/clk/zynqmp/pll.c:61:27: error: 'ret_payload' is used uninitialized [-Werror=uninitialized] 61 | return ret_payload[1]; | ~~~~~~~~~~~^~~ drivers/clk/zynqmp/pll.c: In function 'zynqmp_pll_recalc_rate': drivers/clk/zynqmp/pll.c:53:13: note: 'ret_payload' declared here 53 | u32 ret_payload[PAYLOAD_ARG_CNT]; | ^~~~~~~~~~~ drivers/clk/zynqmp/clk-mux-zynqmp.c: In function 'zynqmp_clk_mux_get_parent': drivers/clk/zynqmp/clk-mux-zynqmp.c:57:16: error: 'val' is used uninitialized [-Werror=uninitialized] 57 | return val; | ^~~ As it was apparently intentional to support this for compile testing purposes, change the code to have just enough error handling for the compiler to not notice the remaining bugs. Fixes: 21f2375 ("clk: zynqmp: Drop dependency on ARCH_ZYNQMP") Co-developed-by: Arnd Bergmann <[email protected]> Signed-off-by: Michal Simek <[email protected]> Link: https://lore.kernel.org/r/f1c4e8c903fe2d5df5413421920a56890a46387a.1624356908.git.michal.simek@xilinx.com Signed-off-by: Stephen Boyd <[email protected]>
1 parent 6efb943 commit 6c9feab

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

drivers/clk/zynqmp/clk-mux-zynqmp.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct zynqmp_clk_mux {
3838
* zynqmp_clk_mux_get_parent() - Get parent of clock
3939
* @hw: handle between common and hardware-specific interfaces
4040
*
41-
* Return: Parent index
41+
* Return: Parent index on success or number of parents in case of error
4242
*/
4343
static u8 zynqmp_clk_mux_get_parent(struct clk_hw *hw)
4444
{
@@ -50,9 +50,15 @@ static u8 zynqmp_clk_mux_get_parent(struct clk_hw *hw)
5050

5151
ret = zynqmp_pm_clock_getparent(clk_id, &val);
5252

53-
if (ret)
53+
if (ret) {
5454
pr_warn_once("%s() getparent failed for clock: %s, ret = %d\n",
5555
__func__, clk_name, ret);
56+
/*
57+
* clk_core_get_parent_by_index() takes num_parents as incorrect
58+
* index which is exactly what I want to return here
59+
*/
60+
return clk_hw_get_num_parents(hw);
61+
}
5662

5763
return val;
5864
}

drivers/clk/zynqmp/pll.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ struct zynqmp_pll {
3131
#define PS_PLL_VCO_MAX 3000000000UL
3232

3333
enum pll_mode {
34-
PLL_MODE_INT,
35-
PLL_MODE_FRAC,
34+
PLL_MODE_INT = 0,
35+
PLL_MODE_FRAC = 1,
36+
PLL_MODE_ERROR = 2,
3637
};
3738

3839
#define FRAC_OFFSET 0x8
@@ -54,9 +55,11 @@ static inline enum pll_mode zynqmp_pll_get_mode(struct clk_hw *hw)
5455
int ret;
5556

5657
ret = zynqmp_pm_get_pll_frac_mode(clk_id, ret_payload);
57-
if (ret)
58+
if (ret) {
5859
pr_warn_once("%s() PLL get frac mode failed for %s, ret = %d\n",
5960
__func__, clk_name, ret);
61+
return PLL_MODE_ERROR;
62+
}
6063

6164
return ret_payload[1];
6265
}
@@ -126,7 +129,7 @@ static long zynqmp_pll_round_rate(struct clk_hw *hw, unsigned long rate,
126129
* @hw: Handle between common and hardware-specific interfaces
127130
* @parent_rate: Clock frequency of parent clock
128131
*
129-
* Return: Current clock frequency
132+
* Return: Current clock frequency or 0 in case of error
130133
*/
131134
static unsigned long zynqmp_pll_recalc_rate(struct clk_hw *hw,
132135
unsigned long parent_rate)
@@ -138,14 +141,21 @@ static unsigned long zynqmp_pll_recalc_rate(struct clk_hw *hw,
138141
unsigned long rate, frac;
139142
u32 ret_payload[PAYLOAD_ARG_CNT];
140143
int ret;
144+
enum pll_mode mode;
141145

142146
ret = zynqmp_pm_clock_getdivider(clk_id, &fbdiv);
143-
if (ret)
147+
if (ret) {
144148
pr_warn_once("%s() get divider failed for %s, ret = %d\n",
145149
__func__, clk_name, ret);
150+
return 0ul;
151+
}
152+
153+
mode = zynqmp_pll_get_mode(hw);
154+
if (mode == PLL_MODE_ERROR)
155+
return 0ul;
146156

147157
rate = parent_rate * fbdiv;
148-
if (zynqmp_pll_get_mode(hw) == PLL_MODE_FRAC) {
158+
if (mode == PLL_MODE_FRAC) {
149159
zynqmp_pm_get_pll_frac_data(clk_id, ret_payload);
150160
data = ret_payload[1];
151161
frac = (parent_rate * data) / FRAC_DIV;

0 commit comments

Comments
 (0)