Skip to contentSkip to conversation

clocksource/drivers/timer-mediatek: Check devm_clk_get_optional_enabled() for errors

PATCH New Ian Rogers 1 participant 1 message Nov 19 Clocksource, clockevent drivers

lore
Share & tools
lore

Ian Rogers

author
#0 lore raw

PATCH 1/1 clocksource/drivers/timer-mediatek: Check devm_clk_get_optional_enabled() for errors

mtk_gpt_init() stores the return value of devm_clk_get_optional_enabled() in 'clk_bus' without checking IS_ERR(clk_bus). If the optional "bus" clock requires probe deferral (-EPROBE_DEFER) or fails to enable, mtk_gpt_init() ignores the error and proceeds to access timer MMIO registers with the bus clock disabled.

Return PTR_ERR(clk_bus) when IS_ERR(clk_bus) is true.

Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with -Wunused-but-set-variable enabled; fix and changelog drafted with an AI coding assistant. Build-tested under LLVM=1 W=1 and -Wunused-but-set-variable (CONFIG_MTK_TIMER=y via CONFIG_COMPILE_TEST); not boot-tested on MediaTek SoC hardware.

Fixes e234d4082380 ("clocksource/drivers/timer-mediatek: Request and enable the bus clock")
---
 drivers/clocksource/timer-mediatek.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-mediatek.c +2 -0
index 842d6ee4259e..860d4eb3f8f7 100644
@@ -314,6 +314,8 @@ static int mtk_gpt_init(struct platform_device *pdev)
 	int ret;
 
 	clk_bus = devm_clk_get_optional_enabled(&pdev->dev, "bus");
+	if (IS_ERR(clk_bus))
+		return PTR_ERR(clk_bus);
 
 	to.clkevt.features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
 	to.clkevt.set_state_shutdown = mtk_gpt_clkevt_shutdown;
Signature · 1 line
2.56.1.708.g77570a6a1d-goog