cpufreq: mediatek: guard error paths to avoid kernel panic
Subsystems (2)
PATCH 1/1 cpufreq: mediatek: guard error paths to avoid kernel panic
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.
--- drivers/cpufreq/mediatek-cpufreq.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/cpufreq/mediatek-cpufreq.c +6 -4
@@ -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 &®ulator_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 &®ulator_is_enabled (info->sram_reg)) +regulator_disable (info->sram_reg);if (!IS_ERR (info->proc_reg))regulator_put (info->proc_reg);
Signature · 1 line
2.40.0
AngeloGioacchino Del Regno
maintainerIl 23/03/23 12:04, Daniel Golle ha scritto:
Quoted 19 lines
Guard pointer access in error path of
mtk_cpu_dvfs_info_init()to make sureinfo->proc_regandinfo->sram_regare 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 <[email protected]>Suggested-by Sam Shih <[email protected]>Signed-off-by Daniel Golle <[email protected]>--- drivers/cpufreq/mediatek-cpufreq.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/cpufreq/mediatek-cpufreq.c +0
-0@@ -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);
drivers/cpufreq/mediatek-cpufreq.c static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu) · line 585
Quoted 10 lines
drivers/cpufreq/mediatek-cpufreq.c +4
-4out_free_resources: -if (regulator_is_enabled (info->proc_reg)) -regulator_disable (info->proc_reg); -if (info->sram_reg &®ulator_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))
For both, actually, if you suspect that (xxxx)_reg may be NULL, then you should use IS_ERR_OR_NULL() instead...
drivers/cpufreq/mediatek-cpufreq.c static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu) · line 586
Quoted 1 line
drivers/cpufreq/mediatek-cpufreq.c +1
-0+if (info->sram_reg &®ulator_is_enabled (info->sram_reg))
...otherwise, here it's useless to check if it's not NULL?
Regards,
Angelo