Skip to contentSkip to conversation

hwmon: (max31790) potential ERR_PTR dereference

PATCH Applied Dan Carpenter 2 participants 2 messages Oct 12, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: (max31790) potential ERR_PTR dereference

We should only dereference "data" after we check if it is an error pointer.

Fixes 54187ff9d766 ('hwmon: (max31790) Convert to use new hwmon registration API')
drivers/hwmon/max31790.c +3 -1
index bef84e0..c1b9275 100644
@@ -268,11 +268,13 @@ static int max31790_read_pwm(struct device *dev, u32 attr, int channel,
 			     long *val)
 {
 	struct max31790_data *data = max31790_update_device(dev);
-	u8 fan_config = data->fan_config[channel];
+	u8 fan_config;
 
 	if (IS_ERR(data))
 		return PTR_ERR(data);
 
+	fan_config = data->fan_config[channel];
+
 	switch (attr) {
 	case hwmon_pwm_input:
 		*val = data->pwm[channel] >> 8;
maintainer Applied
#1 lore raw
Quoted 5 lines · Dan Carpenter

We should only dereference "data" after we check if it is an error pointer.

Fixes 54187ff9d766 ('hwmon: (max31790) Convert to use new hwmon registration API')

Applied.

Thanks,
Guenter

Quoted 24 lines

---
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

drivers/hwmon/max31790.c +3 -1
index bef84e0..c1b9275 100644
@@ -268,11 +268,13 @@ static int max31790_read_pwm(struct device *dev, u32 attr, int channel,
 			     long *val)
 {
 	struct max31790_data *data = max31790_update_device(dev);
-	u8 fan_config = data->fan_config[channel];
+	u8 fan_config;
 
 	if (IS_ERR(data))
 		return PTR_ERR(data);
 
+	fan_config = data->fan_config[channel];
+
 	switch (attr) {
 	case hwmon_pwm_input:
 		*val = data->pwm[channel] >> 8;