PM / devfreq: mediatek: protect oop in critical session

mtk_ccifreq_opp_notifier is reenter function when policy0 / policy6
change freq, so mutex_lock should protect all OPP event.

Link: https://lore.kernel.org/lkml/20230818021741.6173-1-chun-jen.tseng@mediatek.com/T/
Signed-off-by: Mark Tseng <chun-jen.tseng@mediatek.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
This commit is contained in:
Mark Tseng 2023-08-18 10:17:41 +08:00 committed by Chanwoo Choi
parent 8a749fd1a8
commit d280560198

View File

@ -137,6 +137,8 @@ static int mtk_ccifreq_target(struct device *dev, unsigned long *freq,
if (drv->pre_freq == *freq) if (drv->pre_freq == *freq)
return 0; return 0;
mutex_lock(&drv->reg_lock);
inter_voltage = drv->inter_voltage; inter_voltage = drv->inter_voltage;
cci_pll = clk_get_parent(drv->cci_clk); cci_pll = clk_get_parent(drv->cci_clk);
@ -147,8 +149,6 @@ static int mtk_ccifreq_target(struct device *dev, unsigned long *freq,
return PTR_ERR(opp); return PTR_ERR(opp);
} }
mutex_lock(&drv->reg_lock);
voltage = dev_pm_opp_get_voltage(opp); voltage = dev_pm_opp_get_voltage(opp);
dev_pm_opp_put(opp); dev_pm_opp_put(opp);
@ -227,9 +227,9 @@ static int mtk_ccifreq_opp_notifier(struct notifier_block *nb,
drv = container_of(nb, struct mtk_ccifreq_drv, opp_nb); drv = container_of(nb, struct mtk_ccifreq_drv, opp_nb);
if (event == OPP_EVENT_ADJUST_VOLTAGE) { if (event == OPP_EVENT_ADJUST_VOLTAGE) {
mutex_lock(&drv->reg_lock);
freq = dev_pm_opp_get_freq(opp); freq = dev_pm_opp_get_freq(opp);
mutex_lock(&drv->reg_lock);
/* current opp item is changed */ /* current opp item is changed */
if (freq == drv->pre_freq) { if (freq == drv->pre_freq) {
volt = dev_pm_opp_get_voltage(opp); volt = dev_pm_opp_get_voltage(opp);