summaryrefslogtreecommitdiff
path: root/drivers/thermal
diff options
context:
space:
mode:
authorDurgadoss R <durgadoss.r@intel.com>2014-02-07 02:44:08 -0800
committerDiwakar Tundlam <dtundlam@nvidia.com>2014-02-13 16:02:08 -0800
commitf76fb7752dda719bc224f48f696e6cd749c54dc2 (patch)
treef8151a66ac79f307ccf7f0a7cb3ec5e8724ab7e5 /drivers/thermal
parent4d5473964afdcdfaef4dbc50872a48eda1e14845 (diff)
Thermal: Check for validity before doing kfree
The thermal_release function is called whenever any device belonging to 'thermal' class unregisters. This function performs kfree(cdev) without any check. In cases where there are more device registrations other than just 'thermal_zone' and 'cooling_device' this might accidently free memory allocated them silently; and cause memory errors. This patch changes this behavior by doing kfree(cdev) only when the device pointer belongs to a real cdev i.e. cooling_device. Change-Id: I1c06dfcf3a104ad08e9c78a00233a53df17dbea7 Signed-off-by: Durgadoss R <durgadoss.r@intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com> Signed-off-by: Paul Walmsley <pwalmsley@nvidia.com> # for the NVIDIA downstream kernel Reviewed-on: http://git-master/r/356888 Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com> Tested-by: Diwakar Tundlam <dtundlam@nvidia.com>
Diffstat (limited to 'drivers/thermal')
-rw-r--r--drivers/thermal/thermal_core.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index d6668e867dd7..a07140624c58 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1142,7 +1142,8 @@ static void thermal_release(struct device *dev)
sizeof("thermal_zone") - 1)) {
tz = to_thermal_zone(dev);
kfree(tz);
- } else {
+ } else if(!strncmp(dev_name(dev), "cooling_device",
+ sizeof("cooling_device") - 1)){
cdev = to_cooling_device(dev);
kfree(cdev);
}