thermal/debugfs: Free all thermal zone debug memory on zone removal
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 25 Apr 2024 17:52:12 +0000 (19:52 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 26 Apr 2024 09:11:00 +0000 (11:11 +0200)
Because thermal_debug_tz_remove() does not free all memory allocated for
thermal zone diagnostics, some of that memory becomes unreachable after
freeing the thermal zone's struct thermal_debugfs object.

Address this by making thermal_debug_tz_remove() free all of the memory
in question.

Fixes: 7ef01f228c9f ("thermal/debugfs: Add thermal debugfs information for mitigation episodes")
Cc :6.8+ <stable@vger.kernel.org> # 6.8+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
drivers/thermal/thermal_debugfs.c

index d78d54ae2605e8ab3050dd7a1e68fb13688a78c5..8d66b3a96be1a145667ee5db9df2f9c27ffac14f 100644 (file)
@@ -826,15 +826,28 @@ void thermal_debug_tz_add(struct thermal_zone_device *tz)
 void thermal_debug_tz_remove(struct thermal_zone_device *tz)
 {
        struct thermal_debugfs *thermal_dbg = tz->debugfs;
+       struct tz_episode *tze, *tmp;
+       struct tz_debugfs *tz_dbg;
+       int *trips_crossed;
 
        if (!thermal_dbg)
                return;
 
+       tz_dbg = &thermal_dbg->tz_dbg;
+
        mutex_lock(&thermal_dbg->lock);
 
+       trips_crossed = tz_dbg->trips_crossed;
+
+       list_for_each_entry_safe(tze, tmp, &tz_dbg->tz_episodes, node) {
+               list_del(&tze->node);
+               kfree(tze);
+       }
+
        tz->debugfs = NULL;
 
        mutex_unlock(&thermal_dbg->lock);
 
        thermal_debugfs_remove_id(thermal_dbg);
+       kfree(trips_crossed);
 }