diff options
author | Guenter Roeck | 2019-06-07 10:23:24 -0700 |
---|---|---|
committer | Guenter Roeck | 2019-06-23 18:33:01 -0700 |
commit | 0c4a71d36566a783d795025260a7648447453966 (patch) | |
tree | 66cced6f72eac19d6c5e54fd39b59218fdf93f90 /drivers/hwmon | |
parent | 62dbe50591769f6135b3c8a93c8168b3d177a823 (diff) |
hwmon: (max6650) Improve error handling in max6650_update_device
Pass errors from i2c_smbus_read_byte_data() back to the caller of
max6650_update_device().
Cc: Jean-Francois Dagenais <jeff.dagenais@gmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/max6650.c | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c index 6f1a1a6eae46..e65792020ca1 100644 --- a/drivers/hwmon/max6650.c +++ b/drivers/hwmon/max6650.c @@ -157,14 +157,19 @@ static struct max6650_data *max6650_update_device(struct device *dev) { struct max6650_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; + int reg, err = 0; int i; mutex_lock(&data->update_lock); if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { for (i = 0; i < data->nr_fans; i++) { - data->tach[i] = i2c_smbus_read_byte_data(client, - tach_reg[i]); + reg = i2c_smbus_read_byte_data(client, tach_reg[i]); + if (reg < 0) { + err = reg; + goto error; + } + data->tach[i] = reg; } /* @@ -172,15 +177,20 @@ static struct max6650_data *max6650_update_device(struct device *dev) * caused the alarm is removed. Keep the value latched here * for providing the register through different alarm files. */ - data->alarm |= i2c_smbus_read_byte_data(client, - MAX6650_REG_ALARM); - + reg = i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM); + if (reg < 0) { + err = reg; + goto error; + } + data->alarm |= reg; data->last_updated = jiffies; data->valid = true; } +error: mutex_unlock(&data->update_lock); - + if (err) + data = ERR_PTR(err); return data; } @@ -289,8 +299,12 @@ static ssize_t alarm_show(struct device *dev, { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct max6650_data *data = max6650_update_device(dev); - bool alarm = data->alarm & attr->index; + bool alarm; + if (IS_ERR(data)) + return PTR_ERR(data); + + alarm = data->alarm & attr->index; if (alarm) { mutex_lock(&data->update_lock); data->alarm &= ~attr->index; @@ -512,6 +526,9 @@ static int max6650_read(struct device *dev, enum hwmon_sensor_types type, struct max6650_data *data = max6650_update_device(dev); int mode; + if (IS_ERR(data)) + return PTR_ERR(data); + switch (type) { case hwmon_pwm: switch (attr) { |