Skip to content

Commit

Permalink
Thermal: Check for validity before doing kfree
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
durgadoss.r@intel.com authored and Zhang Rui committed Oct 14, 2013
1 parent a822794 commit 732e4c8
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/thermal/thermal_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 732e4c8

Please sign in to comment.