From 277d649bdaed1da651f21f22ef9e101612b2a344 Mon Sep 17 00:00:00 2001 From: Armando Visconti Date: Thu, 1 Feb 2024 12:02:27 +0100 Subject: [PATCH] drivers: sensor: tmp108: fix coverity integer handling issue Fix coverity integer handling issue (CWE-188). Modifying a variable through a pointer of an incompatible type (other than unsigned char) can lead to unpredictable results. Fix: #67965 Coverity-CID: 248434 Signed-off-by: Armando Visconti --- drivers/sensor/tmp108/tmp108.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/sensor/tmp108/tmp108.c b/drivers/sensor/tmp108/tmp108.c index 13480ff7aef8..79f31a305abb 100644 --- a/drivers/sensor/tmp108/tmp108.c +++ b/drivers/sensor/tmp108/tmp108.c @@ -165,6 +165,7 @@ static int tmp108_attr_get(const struct device *dev, struct sensor_value *val) { int result; + uint16_t tmp_val; if (chan != SENSOR_CHAN_AMBIENT_TEMP && chan != SENSOR_CHAN_ALL) { return -ENOTSUP; @@ -174,7 +175,9 @@ static int tmp108_attr_get(const struct device *dev, case SENSOR_ATTR_CONFIGURATION: result = tmp108_reg_read(dev, TI_TMP108_REG_CONF, - (uint16_t *) &(val->val1)); + &tmp_val); + val->val1 = tmp_val; + val->val2 = 0; break; default: return -ENOTSUP;