From 32fa5ba3171116a5501e60245dc97e82fe3cf267 Mon Sep 17 00:00:00 2001 From: Christophe Jaillet Date: Tue, 8 Aug 2017 16:39:52 +0200 Subject: thermal: core: Add some new helper functions to free resources In order to easily free resources allocated by 'thermal_zone_create_device_groups()' we need 2 new helper functions. The first one undoes 'thermal_zone_create_device_groups()'. The 2nd one undoes 'create_trip_attrs()', which is a function called by 'thermal_zone_create_device_groups()'. Signed-off-by: Christophe JAILLET Signed-off-by: Zhang Rui --- drivers/thermal/thermal_sysfs.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'drivers/thermal/thermal_sysfs.c') diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index a694de9..fb80c96 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -605,6 +605,24 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) return 0; } +/** + * destroy_trip_attrs() - destroy attributes for trip points + * @tz: the thermal zone device + * + * helper function to free resources allocated by create_trip_attrs() + */ +static void destroy_trip_attrs(struct thermal_zone_device *tz) +{ + if (!tz) + return; + + kfree(tz->trip_type_attrs); + kfree(tz->trip_temp_attrs); + if (tz->ops->get_trip_hyst) + kfree(tz->trip_hyst_attrs); + kfree(tz->trips_attribute_group.attrs); +} + int thermal_zone_create_device_groups(struct thermal_zone_device *tz, int mask) { @@ -637,6 +655,17 @@ int thermal_zone_create_device_groups(struct thermal_zone_device *tz, return 0; } +void thermal_zone_destroy_device_groups(struct thermal_zone_device *tz) +{ + if (!tz) + return; + + if (tz->trips) + destroy_trip_attrs(tz); + + kfree(tz->device.groups); +} + /* sys I/F for cooling device */ static ssize_t thermal_cooling_device_type_show(struct device *dev, -- cgit v1.1