diff
+	bool remove_debugfs = false;
 	mutex_lock(&thermal_dbg->lock);
 	tz->debugfs = NULL;
+	remove_debugfs = true;
 	mutex_unlock(&thermal_dbg->lock);
-	thermal_debugfs_remove_id(thermal_dbg);
+	if (remove_debugfs)
+		thermal_debugfs_remove_id(thermal_dbg);
