Skip to contentSkip to conversation

hwmon: max31790: fix dereference of ERR_PTR

PATCH In review Sudip Mukherjee 2 participants 2 messages Sep 16, 2015 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: max31790: fix dereference of ERR_PTR

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.

---
 drivers/hwmon/max31790.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/hwmon/max31790.c +4 -4
index f129668..69c0ac8 100644
@@ -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);
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 5 lines · Sudip Mukherjee

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.

Good catch. Applied.

Thanks,
Guenter

Quoted 39 lines
---
  drivers/hwmon/max31790.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/hwmon/max31790.c +4 -4
index f129668..69c0ac8 100644
@@ -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);