[PATCH v4 4/4] iio:temperature:mlx90632: Convert polling while loops to do-while
From: Crt Mori
Date: Sat Aug 08 2020 - 08:14:22 EST
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@xxxxxxxxxxx>
---
drivers/iio/temperature/mlx90632.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
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,
®_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;
--
2.25.1