Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177947017
D61976.1795621827.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
D61976.1795621827.diff
View Options
diff --git a/sys/dev/iicbus/sensor/tmp461.c b/sys/dev/iicbus/sensor/tmp461.c
--- a/sys/dev/iicbus/sensor/tmp461.c
+++ b/sys/dev/iicbus/sensor/tmp461.c
@@ -226,7 +226,7 @@
static int
tmp461_read_temperature(device_t dev, int32_t *temperature, bool remote_measure)
{
- uint8_t data, offset, reg;
+ uint8_t data, config_reg, reg;
struct tmp461_softc *sc;
int error;
@@ -238,7 +238,7 @@
if (error != 0)
goto fail;
- /* trigger sample*/
+ /* trigger sample */
error = tmp461_write_1(dev, TMP461_ONESHOT_REG, 0xFF);
if (error != 0)
goto fail;
@@ -247,27 +247,28 @@
DELAY(TMP461_SENSOR_MAX_CONV_TIME/(1UL<<data));
/* read config register offset */
- error = tmp461_read_1(dev, TMP461_CONFIG_REG_R, &data);
+ error = tmp461_read_1(dev, TMP461_CONFIG_REG_R, &config_reg);
if (error != 0)
goto fail;
- offset = (data & TMP461_CONFIG_REG_TEMP_RANGE_BIT ?
- TMP461_EXTENDED_TEMP_MODIFIER : 0);
-
reg = remote_measure ?
TMP461_GLOBAL_TEMP_REG_MSB : TMP461_LOCAL_TEMP_REG_MSB;
- /* read temeperature value*/
+ /* read temperature value*/
error = tmp461_read_1(dev, reg, &data);
if (error != 0)
goto fail;
- data -= offset;
/*
- * Sign extension has to happen at the end, as left shift of negative
- * signed integer has undefined behavior.
+ * Left shift has to happen first, as at this point we are operating on
+ * a positive number that fits in a 32-bit integer, which is not
+ * necessarily the case after the other operations, then triggering
+ * undefined behavior.
*/
- *temperature = sign_extend_32(data << 4, 11);
+ *temperature = data << 4;
+ *temperature = (config_reg & TMP461_CONFIG_REG_TEMP_RANGE_BIT) != 0 ?
+ *temperature - (TMP461_EXTENDED_TEMP_MODIFIER << 4) :
+ sign_extend_32(*temperature, 11);
if (remote_measure) {
if (sc->conf & TMP461_REMOTE_TEMP_DOUBLE_REG) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 25, 3:50 PM (3 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41987371
Default Alt Text
D61976.1795621827.diff (1 KB)
Attached To
Mode
D61976: TMP461 sensor: Fix temperature reading in extended range mode
Attached
Detach File
Event Timeline