}
 }
 
-static struct class thermal_class = {
-       .name = "thermal",
-       .dev_release = thermal_release,
-};
+static struct class *thermal_class;
 
 static inline
 void print_bind_err_msg(struct thermal_zone_device *tz,
            !ops->set_cur_state)
                return ERR_PTR(-EINVAL);
 
+       if (!thermal_class)
+               return ERR_PTR(-ENODEV);
+
        cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
        if (!cdev)
                return ERR_PTR(-ENOMEM);
        cdev->np = np;
        cdev->ops = ops;
        cdev->updated = false;
-       cdev->device.class = &thermal_class;
+       cdev->device.class = thermal_class;
        cdev->devdata = devdata;
 
        ret = cdev->ops->get_max_state(cdev, &cdev->max_state);
        if (num_trips > 0 && (!ops->get_trip_type || !ops->get_trip_temp) && !trips)
                return ERR_PTR(-EINVAL);
 
+       if (!thermal_class)
+               return ERR_PTR(-ENODEV);
+
        tz = kzalloc(sizeof(*tz), GFP_KERNEL);
        if (!tz)
                return ERR_PTR(-ENOMEM);
 
        tz->ops = ops;
        tz->tzp = tzp;
-       tz->device.class = &thermal_class;
+       tz->device.class = thermal_class;
        tz->devdata = devdata;
        tz->trips = trips;
        tz->num_trips = num_trips;
        if (result)
                goto unregister_netlink;
 
-       result = class_register(&thermal_class);
-       if (result)
+       thermal_class = kzalloc(sizeof(*thermal_class), GFP_KERNEL);
+       if (!thermal_class) {
+               result = -ENOMEM;
+               goto unregister_governors;
+       }
+
+       thermal_class->name = "thermal";
+       thermal_class->dev_release = thermal_release;
+
+       result = class_register(thermal_class);
+       if (result) {
+               kfree(thermal_class);
+               thermal_class = NULL;
                goto unregister_governors;
+       }
 
        result = register_pm_notifier(&thermal_pm_nb);
        if (result)