PM / devfreq: mediatek: Fix possible dereference of null pointer
Subsystems (2)
PATCH 1/1 PM / devfreq: mediatek: Fix possible dereference of null pointer
From: Matthias Brugger <[email protected]>
We dereference the driver data before checking of it's valid. This patch fixes this, by accessing the PLL data struct after cheching the pointer
--- drivers/devfreq/mtk-cci-devfreq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/devfreq/mtk-cci-devfreq.c +2 -1
@@ -127,7 +127,7 @@ static int mtk_ccifreq_target(struct device *dev, unsigned long *freq, u32 flags) {struct mtk_ccifreq_drv *drv =dev_get_drvdata (dev); -struct clk *cci_pll =clk_get_parent (drv->cci_clk); +struct clk *cci_pll;struct dev_pm_opp *opp;unsigned long opp_rate;int voltage, pre_voltage, inter_voltage, target_voltage, ret;
@@ -138,6 +138,7 @@ static int mtk_ccifreq_target(struct device *dev, unsigned long *freq,if (drv->pre_freq == *freq)return 0 ; + cci_pll =clk_get_parent (drv->cci_clk); inter_voltage = drv->inter_voltage; opp_rate = *freq;
Signature · 1 line
2.36.0
AngeloGioacchino Del Regno
maintainerIl 17/06/22 15:33, [email protected] ha scritto:
Quoted 6 lines
From: Matthias Brugger <[email protected]>
We dereference the driver data before checking of it's valid. This patch fixes this, by accessing the PLL data struct after cheching the pointer
Hello Matthias,
honestly, I don't think that this commit is right: mtk_ccifreq_target() is the devfreq_dev_profile's .target() callback!
Checking mtk_ccifreq_probe(), we are setting drvdata long before adding the devfreq device so, actually, it's impossible for dev_get_drvdata(dev) to return NULL, or whatever invalid pointer.
This means that the right thing to do in mtk_ccifreq_target() is to simply remove the drv NULL check, as this can never happen! :-)
Cheers,
Angelo
Quoted 28 lines
Fixes 07dc787be231 ("Add linux-next specific files for 20220617")Signed-off-by Matthias Brugger <[email protected]>--- drivers/devfreq/mtk-cci-devfreq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/devfreq/mtk-cci-devfreq.c +2
-1@@ -127,7 +127,7 @@ static int mtk_ccifreq_target(struct device *dev, unsigned long *freq, u32 flags) {struct mtk_ccifreq_drv *drv =dev_get_drvdata (dev); -struct clk *cci_pll =clk_get_parent (drv->cci_clk); +struct clk *cci_pll;struct dev_pm_opp *opp;unsigned long opp_rate;int voltage, pre_voltage, inter_voltage, target_voltage, ret;@@ -138,6 +138,7 @@ static int mtk_ccifreq_target(struct device *dev, unsigned long *freq,if (drv->pre_freq == *freq)return 0 ; + cci_pll =clk_get_parent (drv->cci_clk); inter_voltage = drv->inter_voltage; opp_rate = *freq;
Matthias Brugger
maintainerQuoted 13 lines · AngeloGioacchino Del Regno
Il 17/06/22 15:33, [email protected] ha scritto:
Quoted 6 lines
From: Matthias Brugger <[email protected]>
We dereference the driver data before checking of it's valid. This patch fixes this, by accessing the PLL data struct after cheching the pointer
Hello Matthias,
honestly, I don't think that this commit is right:
mtk_ccifreq_target()is the devfreq_dev_profile's .target() callback!
Quoted 7 lines
Checking
mtk_ccifreq_probe(), we are setting drvdata long before adding the devfreq device so, actually, it's impossible fordev_get_drvdata(dev)to return NULL, or whatever invalid pointer.This means that the right thing to do in
mtk_ccifreq_target()is to simply remove thedrvNULL check, as this can never happen! :-)
Yes you are right. Probe will error out if drv can't be allocated or cci_clk isn't present. I'll send a new patch.
Thanks,
Matthias
Quoted 33 lines
Cheers,
AngeloQuoted 28 lines
Fixes 07dc787be231 ("Add linux-next specific files for 20220617")Signed-off-by Matthias Brugger <[email protected]>---
drivers/devfreq/mtk-cci-devfreq.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)drivers/devfreq/mtk-cci-devfreq.c +1
-1@@ -127,7 +127,7 @@ static int mtk_ccifreq_target(struct device *dev, unsignedlong *freq, u32 flags) { struct mtk_ccifreq_drv *drv = dev_get_drvdata(dev); - struct clk *cci_pll = clk_get_parent(drv->cci_clk); + struct clk *cci_pll; struct dev_pm_opp *opp; unsigned long opp_rate;int voltage,
pre_voltage,inter_voltage,target_voltage, ret;drivers/devfreq/mtk-cci-devfreq.c +1
-0@@ -138,6 +138,7 @@ static int mtk_ccifreq_target(struct device *dev, unsigned long *freq, if (drv->pre_freq == *freq) return 0; + cci_pll = clk_get_parent(drv->cci_clk); inter_voltage = drv->inter_voltage; opp_rate = *freq;