Skip to content

Commit 1e225dc

Browse files
jilaypandyaabhinavnxp
authored andcommitted
drivers: sensor: uint8_t var cannot be greater than 0xff
SENSOR_XBR818_CLOCKRATE / val->val1 is getting assigned to uint8_t variable which is causing the logically dead issue, this commit is a fix for it. Signed-off-by: Jilay Pandya <jilay.pandya@outlook.com>
1 parent 41b92cc commit 1e225dc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/sensor/xbr818/xbr818.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,14 @@ static int xbr818_attr_set(const struct device *dev, enum sensor_channel chan,
154154
if (val->val1 > SENSOR_XBR818_CLOCKRATE || val->val1 <= 0) {
155155
return -EINVAL;
156156
}
157-
tmp[0] = SENSOR_XBR818_CLOCKRATE / val->val1;
158-
if (tmp[0] > 0xFF) {
157+
const int32_t temp = SENSOR_XBR818_CLOCKRATE / val->val1;
158+
159+
if (temp > 0xFF) {
159160
return -EINVAL;
160161
}
162+
163+
tmp[0] = (uint8_t)temp;
164+
161165
ret = i2c_reg_write_byte_dt(&config->i2c, XBR818_SAMPLE_RATE_DIVIDER, tmp[0]);
162166
} else {
163167
ret = xbr818_disable_i2c(dev);

0 commit comments

Comments
 (0)