Skip to content

Commit 842c375

Browse files
Jiasheng JiangWilliam Breathitt Gray
authored andcommitted
counter: stm32-timer-cnt: Add check for clk_enable()
Add check for the return value of clk_enable() in order to catch the potential exception. Fixes: c5b8425 ("counter: stm32-timer-cnt: add power management support") Fixes: ad29937 ("counter: Add STM32 Timer quadrature encoder") Signed-off-by: Jiasheng Jiang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: William Breathitt Gray <[email protected]>
1 parent 147359e commit 842c375

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

drivers/counter/stm32-timer-cnt.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,17 @@ static int stm32_count_enable_write(struct counter_device *counter,
214214
{
215215
struct stm32_timer_cnt *const priv = counter_priv(counter);
216216
u32 cr1;
217+
int ret;
217218

218219
if (enable) {
219220
regmap_read(priv->regmap, TIM_CR1, &cr1);
220-
if (!(cr1 & TIM_CR1_CEN))
221-
clk_enable(priv->clk);
221+
if (!(cr1 & TIM_CR1_CEN)) {
222+
ret = clk_enable(priv->clk);
223+
if (ret) {
224+
dev_err(counter->parent, "Cannot enable clock %d\n", ret);
225+
return ret;
226+
}
227+
}
222228

223229
regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN,
224230
TIM_CR1_CEN);
@@ -817,7 +823,11 @@ static int __maybe_unused stm32_timer_cnt_resume(struct device *dev)
817823
return ret;
818824

819825
if (priv->enabled) {
820-
clk_enable(priv->clk);
826+
ret = clk_enable(priv->clk);
827+
if (ret) {
828+
dev_err(dev, "Cannot enable clock %d\n", ret);
829+
return ret;
830+
}
821831

822832
/* Restore registers that may have been lost */
823833
regmap_write(priv->regmap, TIM_SMCR, priv->bak.smcr);

0 commit comments

Comments
 (0)