1
0
Fork 0
alistair23-linux/drivers/opp
Dave Gerlach deac8703da PM / OPP: _of_add_opp_table_v2(): increment count only if OPP is added
Currently the _of_add_opp_table_v2 call loops through the OPP nodes in
the operating-points-v2 table in the device tree and calls
_opp_add_static_v2 for each to add them to the table. It counts each
iteration through this loop as an added OPP, however there are cases
where _opp_add_static_v2() returns 0 but no new OPP is added to the
list.

This can happen while adding duplicate OPP or if the OPP isn't supported
by hardware.

Because of this the count variable will contain the number of OPP nodes
in the table in device tree but not necessarily the ones that are
actually added.

As this count value is what is checked to determine if there are any
valid OPPs, if a platform has an operating-points-v2 table with all OPP
nodes containing opp-supported-hw values that are not currently
supported, then _of_add_opp_table_v2 will fail to abort as it should due
to an empty table.

Additionally, since commit 3ba98324e8 ("PM / OPP: Get
performance state using genpd helper"), the same count variable is
compared against the number of OPPs containing performance states and
requires that either all or none have pstates set, however in the case
of any opp table that has any entries that do not get added by
_opp_add_static_v2 due to incompatible opp-supported-hw fields, these
numbers will not match and _of_add_opp_table_v2 will incorrectly fail.

We need to clearly identify all the three cases (success, failure,
unsupported/duplicate OPPs) and then increment count only on success
case. Change return type of _opp_add_static_v2() to return the pointer
to the newly added OPP instead of an integer. This routine now returns a
valid pointer if the OPP is really added, NULL for unsupported or
duplicate OPPs, and error value cased as a pointer on errors.

Ideally the fixes tag in this commit should point back to the commit
that introduced OPP v2 initially, as that's where we started incorrectly
accounting for duplicate OPPs:

commit 274659029c ("PM / OPP: Add support to parse "operating-points-v2" bindings")

But it wasn't a real problem until recently as the count was only used
to check if any OPPs are added or not. And so this commit points to a
rather recent commit where we added more code that depends on the value
of "count".

Fixes: 3ba98324e8 ("PM / OPP: Get performance state using genpd helper")
Reported-by: Dave Gerlach <d-gerlach@ti.com>
Reported-by: Niklas Cassel <niklas.cassel@linaro.org>
Tested-by: Niklas Cassel <niklas.cassel@linaro.org>
Signed-off-by: Dave Gerlach <d-gerlach@ti.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2018-10-04 09:21:36 +05:30
..
Kconfig PM / OPP: Move the OPP directory out of power/ 2017-10-03 02:45:12 +02:00
Makefile PM / OPP: Add ti-opp-supply driver 2017-12-17 19:17:44 +01:00
core.c OPP: Return error on error from dev_pm_opp_get_opp_count() 2018-10-04 09:10:56 +05:30
cpu.c OPP: Don't remove dynamic OPPs from _dev_pm_opp_remove_table() 2018-09-19 14:56:45 -07:00
debugfs.c PM / OPP: "opp-hz" is optional for power domains 2018-05-09 10:15:18 +05:30
of.c PM / OPP: _of_add_opp_table_v2(): increment count only if OPP is added 2018-10-04 09:21:36 +05:30
opp.h OPP: Prevent creating multiple OPP tables for devices sharing OPP nodes 2018-10-01 15:00:31 +05:30
ti-opp-supply.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00