mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] clocksource/drivers/timer-mediatek: Check devm_clk_get_optional_enabled() for errors
@ 2026-11-19 17:06 Ian Rogers
  0 siblings, 0 replies; only message in thread
From: Ian Rogers @ 2026-11-19 17:06 UTC (permalink / raw)
  To: Daniel Lezcano, Thomas Gleixner
  Cc: linux-kernel, llvm, Elkin Cruz, Ian Rogers

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@google.com>
---
 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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-19 17:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 17:06 [PATCH] clocksource/drivers/timer-mediatek: Check devm_clk_get_optional_enabled() for errors Ian Rogers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®