thermal: cpu_cooling: Fix NULL dereference in cpufreq_state2power
authorBrendan Jackman <brendan.jackman@arm.com>
Wed, 17 Aug 2016 15:14:59 +0000 (16:14 +0100)
committerZhang Rui <rui.zhang@intel.com>
Fri, 19 Aug 2016 13:32:18 +0000 (21:32 +0800)
commita305a4387acb01cecadeeea5151c049a022a1bfc
tree4563fb3c6b8956491b1326ba5ec3d160b9850fda
parent694d0d0bb2030d2e36df73e2d23d5770511dbc8d
thermal: cpu_cooling: Fix NULL dereference in cpufreq_state2power

Currently all CPU cooling devices share a
`struct thermal_cooling_device_ops` instance. The thermal core uses the
presence of functions in this struct to determine if a cooling device
has a power model (see cdev_is_power_actor). cpu_cooling.c adds the
power model functions to the shared struct when a device is registered
with a power model.

Therefore, if a CPU cooling device is registered using
[of_]cpufreq_power_cooling_register, _all_ devices will be determined to
have a power model, including any registered with
[of_]cpufreq_cooling_register. This can result in cpufreq_state2power
being called on a device where dyn_power_table is NULL.

With this commit, instead of having a shared thermal_cooling_device_ops
which is mutated, we have two versions: one with the power functions and
one without.

Signed-off-by: Brendan Jackman <brendan.jackman@arm.com>
Cc: Amit Daniel Kachhap <amit.kachhap@gmail.com>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Javi Merino <javi.merino@arm.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Javi Merino <javi.merino@arm.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
drivers/thermal/cpu_cooling.c