Skip to content

Commit be37adc

Browse files
committed
hm0360: _set_pll(): detect read_reg failure before writing PLL1CFG
The old code stored the raw return value of read_reg() in an 8-bit variable and wrote it straight back to PLL1CFG. A negative I²C/SCCB error therefore became 0xFF (or similar), silently corrupting the sensor’s clock tree while still returning “success”. * Read PLL1CFG into an int (`ret`) and return immediately if `ret < 0`. * Cast to uint8_t only after the error check, then proceed with the masked write. This propagates read failures to the caller and guarantees we never write garbage to the PLL register under fault conditions.
1 parent ed74d59 commit be37adc

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

sensors/hm0360.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,12 @@ static int _set_pll(sensor_t *sensor, int bypass, int multiplier, int sys_div, i
358358
value = 0x00;
359359
}
360360

361-
pll_cfg = read_reg(sensor->slv_addr, PLL1CFG);
361+
int ret = read_reg(sensor->slv_addr, PLL1CFG);
362+
if (ret < 0) {
363+
return ret;
364+
}
365+
366+
pll_cfg = (uint8_t)ret;
362367
return write_reg(sensor->slv_addr, PLL1CFG, (pll_cfg & 0xFC) | value);
363368
}
364369

0 commit comments

Comments
 (0)