Skip to content

Commit 7b3825e

Browse files
nunojsajic23
authored andcommitted
iio: adc: max11410: fix read_poll_timeout() usage
Even though we are passing 'ret' as stop condition for read_poll_timeout(), that return code is still being ignored. The reason is that the poll will stop if the passed condition is true which will happen if the passed op() returns error. However, read_poll_timeout() returns 0 if the *complete* condition evaluates to true. Therefore, the error code returned by op() will be ignored. To fix this we need to check for both error codes: * The one returned by read_poll_timeout() which is either 0 or ETIMEDOUT. * The one returned by the passed op(). Fixes: a44ef7c ("iio: adc: add max11410 adc driver") Signed-off-by: Nuno Sá <nuno.sa@analog.com> Acked-by: Ibrahim Tilki <Ibrahim.Tilki@analog.com> Link: https://lore.kernel.org/r/20230307095303.713251-1-nuno.sa@analog.com Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent c370118 commit 7b3825e

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

drivers/iio/adc/max11410.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,17 @@ static int max11410_sample(struct max11410_state *st, int *sample_raw,
413413
if (!ret)
414414
return -ETIMEDOUT;
415415
} else {
416+
int ret2;
417+
416418
/* Wait for status register Conversion Ready flag */
417-
ret = read_poll_timeout(max11410_read_reg, ret,
418-
ret || (val & MAX11410_STATUS_CONV_READY_BIT),
419+
ret = read_poll_timeout(max11410_read_reg, ret2,
420+
ret2 || (val & MAX11410_STATUS_CONV_READY_BIT),
419421
5000, MAX11410_CONVERSION_TIMEOUT_MS * 1000,
420422
true, st, MAX11410_REG_STATUS, &val);
421423
if (ret)
422424
return ret;
425+
if (ret2)
426+
return ret2;
423427
}
424428

425429
/* Read ADC Data */
@@ -850,17 +854,21 @@ static int max11410_init_vref(struct device *dev,
850854

851855
static int max11410_calibrate(struct max11410_state *st, u32 cal_type)
852856
{
853-
int ret, val;
857+
int ret, ret2, val;
854858

855859
ret = max11410_write_reg(st, MAX11410_REG_CAL_START, cal_type);
856860
if (ret)
857861
return ret;
858862

859863
/* Wait for status register Calibration Ready flag */
860-
return read_poll_timeout(max11410_read_reg, ret,
861-
ret || (val & MAX11410_STATUS_CAL_READY_BIT),
862-
50000, MAX11410_CALIB_TIMEOUT_MS * 1000, true,
863-
st, MAX11410_REG_STATUS, &val);
864+
ret = read_poll_timeout(max11410_read_reg, ret2,
865+
ret2 || (val & MAX11410_STATUS_CAL_READY_BIT),
866+
50000, MAX11410_CALIB_TIMEOUT_MS * 1000, true,
867+
st, MAX11410_REG_STATUS, &val);
868+
if (ret)
869+
return ret;
870+
871+
return ret2;
864872
}
865873

866874
static int max11410_self_calibrate(struct max11410_state *st)

0 commit comments

Comments
 (0)