
+static inline void *safe_deref(void *ptr, size_t offset) {
+    return ptr ? *(void **)((char *)ptr + offset) : NULL;
+}

void thermal_debug_cdev_remove(struct thermal_cooling_device *cdev)
{
-   struct thermal_debugfs *thermal_dbg = cdev->debugfs;
+   struct thermal_debugfs *thermal_dbg = safe_deref(cdev, offsetof(struct thermal_cooling_device, debugfs));
    // ... rest of the function
