diff
--- a/drivers/thermal/thermal_sys.c
+++ b/drivers/thermal/thermal_sys.c
@@ -1532,6 +1532,9 @@ void thermal_debug_cdev_remove(struct thermal_cooling_device *cdev)
 {
 	struct thermal_debugfs *thermal_dbg = cdev->debugfs;
 
+	if (!cdev)
+		return;
+
 	debugfs_remove_recursive(thermal_dbg->debugfs_dir);
 	kfree(thermal_dbg);
 }

