thermal: core: Add some new helper functions to free resources
authorChristophe Jaillet <christophe.jaillet@wanadoo.fr>
Tue, 8 Aug 2017 14:39:52 +0000 (16:39 +0200)
committerZhang Rui <rui.zhang@intel.com>
Fri, 11 Aug 2017 03:33:49 +0000 (11:33 +0800)
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 <christophe.jaillet@wanadoo.fr>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
drivers/thermal/thermal_core.h
drivers/thermal/thermal_sysfs.c

index 2412b3759e16c0404b0dd803a9328c23ac6116a5..27e3b1df73608a860b82fcb5ec993f3aa0655821 100644 (file)
@@ -71,6 +71,7 @@ int thermal_build_list_of_policies(char *buf);
 
 /* sysfs I/F */
 int thermal_zone_create_device_groups(struct thermal_zone_device *, int);
+void thermal_zone_destroy_device_groups(struct thermal_zone_device *);
 void thermal_cooling_device_setup_sysfs(struct thermal_cooling_device *);
 /* used only at binding time */
 ssize_t
index a694de907a266b6c9661545d77de513c0e890365..fb80c96d8f73a52a6d821a3bd57b78c08b6f5e26 100644 (file)
@@ -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,