hwmon: (max31790) Fix dereference of ERR_PTR
authorSudip Mukherjee <sudipm.mukherjee@gmail.com>
Wed, 16 Sep 2015 14:02:59 +0000 (19:32 +0530)
committerGuenter Roeck <linux@roeck-us.net>
Wed, 14 Oct 2015 14:57:14 +0000 (07:57 -0700)
max31790_update_device() return the error code in ERR_PTR. We were
checking if it has returned error or not but before checking we have
dereferenced it.

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/max31790.c

index f1296680833a42ec1d1b95d314e00219b3906792..69c0ac80a946323f8664be96e9a38381a0e9a7a2 100644 (file)
@@ -174,12 +174,12 @@ static ssize_t get_fan(struct device *dev,
 {
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct max31790_data *data = max31790_update_device(dev);
-       int sr = get_tach_period(data->fan_dynamics[attr->index]);
-       int rpm;
+       int sr, rpm;
 
        if (IS_ERR(data))
                return PTR_ERR(data);
 
+       sr = get_tach_period(data->fan_dynamics[attr->index]);
        rpm = RPM_FROM_REG(data->tach[attr->index], sr);
 
        return sprintf(buf, "%d\n", rpm);
@@ -190,12 +190,12 @@ static ssize_t get_fan_target(struct device *dev,
 {
        struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct max31790_data *data = max31790_update_device(dev);
-       int sr = get_tach_period(data->fan_dynamics[attr->index]);
-       int rpm;
+       int sr, rpm;
 
        if (IS_ERR(data))
                return PTR_ERR(data);
 
+       sr = get_tach_period(data->fan_dynamics[attr->index]);
        rpm = RPM_FROM_REG(data->target_count[attr->index], sr);
 
        return sprintf(buf, "%d\n", rpm);