From: Dan Carpenter Date: Fri, 14 Oct 2022 09:39:52 +0000 (+0300) Subject: iio: imu: bno055: uninitialized variable bug in bno055_trigger_handler() X-Git-Tag: v6.6.17~6170^2~12^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dd4753f88f242f46d0d8726f5936f64e754a47f2;p=platform%2Fkernel%2Flinux-rpi.git 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 Acked-by: Nuno Sá Link: https://lore.kernel.org/r/Y0kuaO9PQkSQja+A@kili Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/imu/bno055/bno055.c b/drivers/iio/imu/bno055/bno055.c index 307557a..52744dd 100644 --- a/drivers/iio/imu/bno055/bno055.c +++ b/drivers/iio/imu/bno055/bno055.c @@ -632,7 +632,7 @@ static int bno055_set_regmask(struct bno055_priv *priv, int val, int val2, return -EINVAL; } delta = abs(tbl_val - req_val); - if (delta < best_delta || first) { + if (first || delta < best_delta) { best_delta = delta; hwval = i; first = false;