Commit f75c544d authored by Herve Codina's avatar Herve Codina Committed by Mark Brown

iio: inkern: Check error explicitly in iio_channel_read_max()

The current implementation returns the error code as part of the
default switch case.
This can lead to returning an incorrect positive value in case of
iio_avail_type enum entries evolution.

In order to avoid this case, be more strict in error checking.
Signed-off-by: default avatarHerve Codina <herve.codina@bootlin.com>
Acked-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
Link: https://lore.kernel.org/r/20230623085830.749991-4-herve.codina@bootlin.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent b5f34841
......@@ -858,6 +858,9 @@ static int iio_channel_read_max(struct iio_channel *chan,
val2 = &unused;
ret = iio_channel_read_avail(chan, &vals, type, &length, info);
if (ret < 0)
return ret;
switch (ret) {
case IIO_AVAIL_RANGE:
switch (*type) {
......@@ -888,7 +891,7 @@ static int iio_channel_read_max(struct iio_channel *chan,
return 0;
default:
return ret;
return -EINVAL;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment