From: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx> Switch the ||'d conditions around to ensure we don't check a value that hasn't been initialized yet. Also fix a warning due to lack of visibility that the initialization path will always run by setting the array index to 0 at definition. Fixes: 4aefe1c2bd0c ("iio: imu: add Bosch Sensortec BNO055 core driver") Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx> Cc: Andrea Merello <andrea.merello@xxxxxx> --- drivers/iio/imu/bno055/bno055.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iio/imu/bno055/bno055.c b/drivers/iio/imu/bno055/bno055.c index 307557a609e3..0938082d5cf8 100644 --- a/drivers/iio/imu/bno055/bno055.c +++ b/drivers/iio/imu/bno055/bno055.c @@ -581,11 +581,11 @@ static int bno055_set_regmask(struct bno055_priv *priv, int val, int val2, { const int shift = __ffs(mask); int best_delta; + int hwval = 0; int req_val; int tbl_val; bool first; int delta; - int hwval; int ret; int len; int i; @@ -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; -- 2.37.2