OPP: Fix crashing when current OPP has unsupportable voltage
Subsystems (2)
PATCH 1/1 OPP: Fix crashing when current OPP has unsupportable voltage
Fix NULL dereference caused by a typo in the code. In particular it happens when CPU is running on a frequency which has unsupportable voltage (by regulator) defined in the OPP table and a custom set_opp() callback is being used. The problem was spotted during of testing of upcoming update for the NVIDIA Tegra CPUFreq driver.
--- drivers/opp/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/opp/core.c +1 -1
@@ -685,7 +685,7 @@ static int _set_opp_custom(const struct opp_table *opp_table, data->old_opp.rate = old_freq; size =sizeof (*old_supply) * opp_table->regulator_count; -if (IS_ERR (old_supply)) +if (!old_supply)memset (data->old_opp.supplies,0 , size);else memcpy (data->old_opp.supplies, old_supply, size);
Signature · 1 line
2.22.0
Quoted 19 lines · Dmitry Osipenko
Fix NULL dereference caused by a typo in the code. In particular it happens when CPU is running on a frequency which has unsupportable voltage (by regulator) defined in the OPP table and a custom
set_opp()callback is being used. The problem was spotted during of testing of upcoming update for the NVIDIA Tegra CPUFreq driver.Cc stable <[email protected]>Fixes 7e535993fa4f ("OPP: Separate out custom OPP handler specific code")Reported-by Marc Dietrich <[email protected]>Signed-off-by Dmitry Osipenko <[email protected]>--- drivers/opp/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/opp/core.c +0
-0
drivers/opp/core.c static int _set_opp_custom(const struct opp_table *opp_table, · line 691
Quoted 8 lines
drivers/opp/core.c +1
-1@@ -685,7 +685,7 @@ static int _set_opp_custom(const struct opp_table *opp_table, data->old_opp.rate = old_freq; size =sizeof (*old_supply) * opp_table->regulator_count; -if (IS_ERR (old_supply)) +if (!old_supply)memset (data->old_opp.supplies,0 , size);else memcpy (data->old_opp.supplies, old_supply, size);
While the change is fine, the commit log isn't. It isn't about unsupportable voltage but frequency. The frequency the CPU is currently running at, is not present in the OPP table and so there is no corresponding OPP, hence no voltage supplies.
I have applied this patch with following change log:
commit 560d1bcad715c215e7ffe5d7cffe045974b623d0 (HEAD -> opp/linux-next)
Author: Dmitry Osipenko <[email protected]> Date: Sun Jun 23 20:50:53 2019 +0300
opp: Don't use IS_ERR on invalid supplies
_set_opp_custom() receives a set of OPP supplies as its arguments and the caller of it passes NULL when the supplies are not valid. But _set_opp_custom(), by mistake, checks for error by performing IS_ERR(old_supply) on it which will always evaluate to false.
The problem was spotted during of testing of upcoming update for the NVIDIA Tegra CPUFreq driver.
--- drivers/opp/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 1 line
viresh
24.06.2019 10:18, Viresh Kumar пишет:
Quoted 21 lines · Dmitry Osipenko
Quoted 20 lines
Fix NULL dereference caused by a typo in the code. In particular it happens when CPU is running on a frequency which has unsupportable voltage (by regulator) defined in the OPP table and a custom
set_opp()callback is being used. The problem was spotted during of testing of upcoming update for the NVIDIA Tegra CPUFreq driver.Cc stable <[email protected]>Fixes 7e535993fa4f ("OPP: Separate out custom OPP handler specific code")Reported-by Marc Dietrich <[email protected]>Signed-off-by Dmitry Osipenko <[email protected]>--- drivers/opp/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/opp/core.c +0
-0@@ -685,7 +685,7 @@ static int _set_opp_custom(const struct opp_table *opp_table,
Quoted 12 lines
drivers/opp/core.c static int _set_opp_custom(const struct opp_table *opp_table, · line 691
Quoted 7 lines
drivers/opp/core.c +1
-1data->old_opp.rate = old_freq; size =sizeof (*old_supply) * opp_table->regulator_count; -if (IS_ERR (old_supply)) +if (!old_supply)memset (data->old_opp.supplies,0 , size);else memcpy (data->old_opp.supplies, old_supply, size);While the change is fine, the commit log isn't. It isn't about unsupportable voltage but frequency. The frequency the CPU is currently running at, is not present in the OPP table and so there is no corresponding OPP, hence no voltage supplies.
Ah, indeed! Looks like the reason for old OPP not being found was caused by the appropriate OPP being disabled because of unsupportable voltage. The offending higher "unsupportable" CPU freq was left after bootloader.
Quoted 22 lines
I have applied this patch with following change log:
commit
560d1bcad715c215e7ffe5d7cffe045974b623d0(HEAD -> opp/linux-next)Author: Dmitry Osipenko <[email protected]> Date: Sun Jun 23 20:50:53 2019 +0300opp: Don't use
IS_ERRon invalid supplies
_set_opp_custom()receives a set of OPP supplies as its arguments and the caller of it passes NULL when the supplies are not valid. But_set_opp_custom(), by mistake, checks for error by performingIS_ERR(old_supply)on it which will always evaluate to false.The problem was spotted during of testing of upcoming update for the NVIDIA Tegra CPUFreq driver.
Cc stable <[email protected]>Fixes 7e535993fa4f ("OPP: Separate out custom OPP handler specific code")Reported-by Marc Dietrich <[email protected]>Signed-off-by Dmitry Osipenko <[email protected]>[ Viresh: Massaged changelog ]Signed-off-by Viresh Kumar <[email protected]>
Quoted 3 lines
--- drivers/opp/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Thank you very much!