static long get_target_state(struct thermal_zone_device *tz,
                struct thermal_cooling_device *cdev, int percentage, int level)
 {
-       unsigned long max_state;
-
-       cdev->ops->get_max_state(cdev, &max_state);
-
-       return (long)(percentage * level * max_state) / (100 * tz->num_trips);
+       return (long)(percentage * level * cdev->max_state) / (100 * tz->num_trips);
 }
 
 /**
 
        struct thermal_instance *pos;
        struct thermal_zone_device *pos1;
        struct thermal_cooling_device *pos2;
-       unsigned long max_state;
-       int result, ret;
+       int result;
 
        if (trip >= tz->num_trips || trip < 0)
                return -EINVAL;
        if (tz != pos1 || cdev != pos2)
                return -EINVAL;
 
-       ret = cdev->ops->get_max_state(cdev, &max_state);
-       if (ret)
-               return ret;
-
        /* lower default 0, upper default max_state */
        lower = lower == THERMAL_NO_LIMIT ? 0 : lower;
-       upper = upper == THERMAL_NO_LIMIT ? max_state : upper;
+       upper = upper == THERMAL_NO_LIMIT ? cdev->max_state : upper;
 
-       if (lower > upper || upper > max_state)
+       if (lower > upper || upper > cdev->max_state)
                return -EINVAL;
 
        dev = kzalloc(sizeof(*dev), GFP_KERNEL);
        cdev->updated = false;
        cdev->device.class = &thermal_class;
        cdev->devdata = devdata;
+
+       if (cdev->ops->get_max_state(cdev, &cdev->max_state))
+               goto out_kfree_type;
+
        thermal_cooling_device_setup_sysfs(cdev);
        ret = device_register(&cdev->device);
        if (ret)
 
                              char *buf)
 {
        struct thermal_cooling_device *cdev = to_cooling_device(dev);
-       unsigned long state;
-       int ret;
 
-       ret = cdev->ops->get_max_state(cdev, &state);
-       if (ret)
-               return ret;
-       return sprintf(buf, "%ld\n", state);
+       return sprintf(buf, "%ld\n", cdev->max_state);
 }
 
 static ssize_t cur_state_show(struct device *dev, struct device_attribute *attr,
        if ((long)state < 0)
                return -EINVAL;
 
+       /* Requested state should be less than max_state + 1 */
+       if (state > cdev->max_state)
+               return -EINVAL;
+
        mutex_lock(&cdev->lock);
 
        result = cdev->ops->set_cur_state(cdev, state);