diff mbox series

[v4,4/4] iio:temperature:mlx90632: Convert polling while loops to do-while

Message ID 20200808121026.1300375-5-cmo@melexis.com
State New
Headers show
Series iio: temperature: mlx90632: Add extended calibration calculations | expand

Commit Message

Crt Mori Aug. 8, 2020, 12:10 p.m. UTC
Reduce number of lines and improve readability to convert polling while
loops to do-while. The iopoll.h interface was not used, because we
require more than 20ms timeout, because time for sensor to perform a
measurement is around 10ms and it needs to perform measurements for each
channel (which currently is 3).

Signed-off-by: Crt Mori <cmo@melexis.com>
---
 drivers/iio/temperature/mlx90632.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/drivers/iio/temperature/mlx90632.c b/drivers/iio/temperature/mlx90632.c
index 4e0131705c11..24ffcce9ad74 100644
--- a/drivers/iio/temperature/mlx90632.c
+++ b/drivers/iio/temperature/mlx90632.c
@@ -214,15 +214,13 @@  static int mlx90632_perform_measurement(struct mlx90632_data *data)
 	if (ret < 0)
 		return ret;
 
-	while (tries-- > 0) {
+	do {
 		ret = regmap_read(data->regmap, MLX90632_REG_STATUS,
 				  &reg_status);
 		if (ret < 0)
 			return ret;
-		if (reg_status & MLX90632_STAT_DATA_RDY)
-			break;
 		usleep_range(10000, 11000);
-	}
+	} while (!(reg_status & MLX90632_STAT_DATA_RDY) && tries--);
 
 	if (tries < 0) {
 		dev_err(&data->client->dev, "data not ready");
@@ -419,7 +417,7 @@  static int mlx90632_read_object_raw_extended(struct regmap *regmap, s16 *object_
 static int mlx90632_read_all_channel_extended(struct mlx90632_data *data, s16 *object_new_raw,
 					      s16 *ambient_new_raw, s16 *ambient_old_raw)
 {
-	int tries = 4;
+	int tries = 5;
 	int ret;
 
 	mutex_lock(&data->lock);
@@ -427,14 +425,13 @@  static int mlx90632_read_all_channel_extended(struct mlx90632_data *data, s16 *o
 	if (ret < 0)
 		goto read_unlock;
 
-	while (tries-- > 0) {
+	do {
 		ret = mlx90632_perform_measurement(data);
 		if (ret < 0)
 			goto read_unlock;
 
-		if (ret == 19)
-			break;
-	}
+	} while ((ret != 19) && tries--);
+
 	if (tries < 0) {
 		ret = -ETIMEDOUT;
 		goto read_unlock;