Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: imu: bno055: uninitialized variable bug in bno055_trigger_handler()

This bug is basically harmless, although it will trigger a runtime warning
if you use KMSan. On the first iteration through the loop, the
"best_delta" variable is uninitialized so re-order the condition to
prevent reading uninitialized memory.

Fixes: 4aefe1c2bd0c ("iio: imu: add Bosch Sensortec BNO055 core driver")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Nuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/Y0kuaO9PQkSQja+A@kili
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Dan Carpenter and committed by
Jonathan Cameron
dd4753f8 65f20301

+1 -1
+1 -1
drivers/iio/imu/bno055/bno055.c
··· 632 632 return -EINVAL; 633 633 } 634 634 delta = abs(tbl_val - req_val); 635 - if (delta < best_delta || first) { 635 + if (first || delta < best_delta) { 636 636 best_delta = delta; 637 637 hwval = i; 638 638 first = false;