Skip to content

Commit bcccc3a

Browse files
David BrownellMark M. Hoffman
authored andcommitted
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: David Brownell <[email protected]> Acked-by: Jean Delvare <[email protected]> Signed-off-by: Mark M. Hoffman <[email protected]>
1 parent b3aeab0 commit bcccc3a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

drivers/hwmon/lm75.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,13 @@ static int lm75_detach_client(struct i2c_client *client)
251251
the SMBus standard. */
252252
static int lm75_read_value(struct i2c_client *client, u8 reg)
253253
{
254+
int value;
255+
254256
if (reg == LM75_REG_CONF)
255257
return i2c_smbus_read_byte_data(client, reg);
256-
else
257-
return swab16(i2c_smbus_read_word_data(client, reg));
258+
259+
value = i2c_smbus_read_word_data(client, reg);
260+
return (value < 0) ? value : swab16(value);
258261
}
259262

260263
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)
287290
int i;
288291
dev_dbg(&client->dev, "Starting lm75 update\n");
289292

290-
for (i = 0; i < ARRAY_SIZE(data->temp); i++)
291-
data->temp[i] = lm75_read_value(client,
292-
LM75_REG_TEMP[i]);
293+
for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
294+
int status;
295+
296+
status = lm75_read_value(client, LM75_REG_TEMP[i]);
297+
if (status < 0)
298+
dev_dbg(&client->dev, "reg %d, err %d\n",
299+
LM75_REG_TEMP[i], status);
300+
else
301+
data->temp[i] = status;
302+
}
293303
data->last_updated = jiffies;
294304
data->valid = 1;
295305
}

0 commit comments

Comments
 (0)