[PATCH] clocksource/drivers/timer-mediatek: Check devm_clk_get_optional_enabled() for errors
From: Ian Rogers
Date: Thu Nov 19 2026 - 12:07:27 EST
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")
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
drivers/clocksource/timer-mediatek.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/clocksource/timer-mediatek.c b/drivers/clocksource/timer-mediatek.c
index 842d6ee4259e..860d4eb3f8f7 100644
--- a/drivers/clocksource/timer-mediatek.c
+++ b/drivers/clocksource/timer-mediatek.c
@@ -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;
--
2.56.1.708.g77570a6a1d-goog