Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH] cpufreq: mediatek: guard error paths to avoid kernel panic
@ 2023-03-23 11:04 Daniel Golle
  2023-03-23 11:43 ` AngeloGioacchino Del Regno
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Golle @ 2023-03-23 11:04 UTC (permalink / raw)
  To: linux-pm, linux-mediatek, linux-arm-kernel, linux-kernel,
	Rafael J. Wysocki, Viresh Kumar, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: Sam Shih, John Crispin

Guard pointer access in error path of mtk_cpu_dvfs_info_init() to
make sure info->proc_reg and info->sram_reg are valid pointers before
accessing them, which would result in kernel panic e.g. in case of
them being set to -EPROBE_DEFER.

Fixes: 4b9ceb757bbb ("cpufreq: mediatek: Enable clocks and regulators")
Reported-by: Sam Shih <sam.shih@mediatek.com>
Suggested-by: Sam Shih <sam.shih@mediatek.com>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
 drivers/cpufreq/mediatek-cpufreq.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-cpufreq.c
index 4466d0c91a6a..980a31ddd0f2 100644
--- a/drivers/cpufreq/mediatek-cpufreq.c
+++ b/drivers/cpufreq/mediatek-cpufreq.c
@@ -579,10 +579,12 @@ static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
 	dev_pm_opp_of_cpumask_remove_table(&info->cpus);
 
 out_free_resources:
-	if (regulator_is_enabled(info->proc_reg))
-		regulator_disable(info->proc_reg);
-	if (info->sram_reg && regulator_is_enabled(info->sram_reg))
-		regulator_disable(info->sram_reg);
+	if (!IS_ERR(info->proc_reg))
+		if (regulator_is_enabled(info->proc_reg))
+			regulator_disable(info->proc_reg);
+	if (!IS_ERR(info->sram_reg))
+		if (info->sram_reg && regulator_is_enabled(info->sram_reg))
+			regulator_disable(info->sram_reg);
 
 	if (!IS_ERR(info->proc_reg))
 		regulator_put(info->proc_reg);
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-23 11:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-23 11:04 [PATCH] cpufreq: mediatek: guard error paths to avoid kernel panic Daniel Golle
2023-03-23 11:43 ` AngeloGioacchino Del Regno

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