diff mbox series

iio: imu: bno055: Fix some uninitialized variable usage

Message ID 20221002145324.3776484-1-jic23@kernel.org (mailing list archive)
State Superseded
Headers show
Series iio: imu: bno055: Fix some uninitialized variable usage | expand

Commit Message

Jonathan Cameron Oct. 2, 2022, 2:53 p.m. UTC
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

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@oracle.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Andrea Merello <andrea.merello@iit.it>
---
 drivers/iio/imu/bno055/bno055.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

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;