Skip to content

Commit 5df96d1

Browse files
masneybclaudiubeznea
authored andcommitted
clk: microchip: core: correct return value on *_get_parent()
roclk_get_parent() and sclk_get_parent() has the possibility of returning -EINVAL, however the framework expects this call to always succeed since the return value is unsigned. If there is no parent map defined, then the current value programmed in the hardware is used. Let's use that same value in the case where -EINVAL is currently returned. This index is only used by clk_core_get_parent_by_index(), and it validates that it doesn't overflow the number of available parents. Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Closes: https://lore.kernel.org/r/202512050233.R9hAWsJN-lkp@intel.com/ Signed-off-by: Brian Masney <bmasney@redhat.com> Reviewed-by: Claudiu Beznea <claudiu.beznea@tuxon.dev> Link: https://lore.kernel.org/r/20251205-clk-microchip-fixes-v3-2-a02190705e47@redhat.com Signed-off-by: Claudiu Beznea <claudiu.beznea@tuxon.dev>
1 parent d93faac commit 5df96d1

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

drivers/clk/microchip/clk-core.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,13 @@ static u8 roclk_get_parent(struct clk_hw *hw)
283283

284284
v = (readl(refo->ctrl_reg) >> REFO_SEL_SHIFT) & REFO_SEL_MASK;
285285

286-
if (!refo->parent_map)
287-
return v;
288-
289-
for (i = 0; i < clk_hw_get_num_parents(hw); i++)
290-
if (refo->parent_map[i] == v)
291-
return i;
286+
if (refo->parent_map) {
287+
for (i = 0; i < clk_hw_get_num_parents(hw); i++)
288+
if (refo->parent_map[i] == v)
289+
return i;
290+
}
292291

293-
return -EINVAL;
292+
return v;
294293
}
295294

296295
static unsigned long roclk_calc_rate(unsigned long parent_rate,
@@ -817,13 +816,13 @@ static u8 sclk_get_parent(struct clk_hw *hw)
817816

818817
v = (readl(sclk->mux_reg) >> OSC_CUR_SHIFT) & OSC_CUR_MASK;
819818

820-
if (!sclk->parent_map)
821-
return v;
819+
if (sclk->parent_map) {
820+
for (i = 0; i < clk_hw_get_num_parents(hw); i++)
821+
if (sclk->parent_map[i] == v)
822+
return i;
823+
}
822824

823-
for (i = 0; i < clk_hw_get_num_parents(hw); i++)
824-
if (sclk->parent_map[i] == v)
825-
return i;
826-
return -EINVAL;
825+
return v;
827826
}
828827

829828
static int sclk_set_parent(struct clk_hw *hw, u8 index)

0 commit comments

Comments
 (0)