]> git.karo-electronics.de Git - linux-beck.git/commitdiff
Thermal: Check for validity before doing kfree
authordurgadoss.r@intel.com <durgadoss.r@intel.com>
Tue, 1 Oct 2013 18:38:00 +0000 (00:08 +0530)
committerZhang Rui <rui.zhang@intel.com>
Mon, 14 Oct 2013 05:11:09 +0000 (13:11 +0800)
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.

Signed-off-by: Durgadoss R <durgadoss.r@intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
drivers/thermal/thermal_core.c

index 4962a6aaf2957d737dfadc2376e803d5d849ff7b..db99b334712a3ee0720af40537fcefb0e2ed327d 100644 (file)
@@ -1038,7 +1038,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);
        }