clocksource/drivers/timer-mediatek: Check devm_clk_get_optional_enabled() for errors
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.
--- drivers/clocksource/timer-mediatek.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/clocksource/timer-mediatek.c +2 -0
@@ -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