c
struct thermal_debugfs {
    // ... existing members
    atomic_int ref_count;
};

void thermal_debug_tz_remove(struct thermal_zone_device *tz)
{
    if (!tz || !tz->debugfs)
        return;

    struct thermal_debugfs *thermal_dbg = tz->debugfs;
    
    if (atomic_fetch_sub(&thermal_dbg->ref_count, 1) > 1)
        return;

    mutex_lock(&thermal_dbg->lock);
    // ... rest of the function
}
