Commit bcccc3a2 authored by David Brownell's avatar David Brownell Committed by Mark M. Hoffman

hwmon: (lm75) sensor reading bugfix

LM75 sensor reading bugfix: never save error status as valid
sensor output.  This could be improved, but at least this
prevents certain rude failure modes.
Signed-off-by: default avatarDavid Brownell <dbrownell@users.sourceforge.net>
Acked-by: default avatarJean Delvare <khali@linux-fr.org>
Signed-off-by: default avatarMark M. Hoffman <mhoffman@lightlink.com>
parent b3aeab0c
...@@ -251,10 +251,13 @@ static int lm75_detach_client(struct i2c_client *client) ...@@ -251,10 +251,13 @@ static int lm75_detach_client(struct i2c_client *client)
the SMBus standard. */ the SMBus standard. */
static int lm75_read_value(struct i2c_client *client, u8 reg) static int lm75_read_value(struct i2c_client *client, u8 reg)
{ {
int value;
if (reg == LM75_REG_CONF) if (reg == LM75_REG_CONF)
return i2c_smbus_read_byte_data(client, reg); return i2c_smbus_read_byte_data(client, reg);
else
return swab16(i2c_smbus_read_word_data(client, reg)); value = i2c_smbus_read_word_data(client, reg);
return (value < 0) ? value : swab16(value);
} }
static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value) static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value)
...@@ -287,9 +290,16 @@ static struct lm75_data *lm75_update_device(struct device *dev) ...@@ -287,9 +290,16 @@ static struct lm75_data *lm75_update_device(struct device *dev)
int i; int i;
dev_dbg(&client->dev, "Starting lm75 update\n"); dev_dbg(&client->dev, "Starting lm75 update\n");
for (i = 0; i < ARRAY_SIZE(data->temp); i++) for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
data->temp[i] = lm75_read_value(client, int status;
LM75_REG_TEMP[i]);
status = lm75_read_value(client, LM75_REG_TEMP[i]);
if (status < 0)
dev_dbg(&client->dev, "reg %d, err %d\n",
LM75_REG_TEMP[i], status);
else
data->temp[i] = status;
}
data->last_updated = jiffies; data->last_updated = jiffies;
data->valid = 1; data->valid = 1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment