summaryrefslogtreecommitdiff
path: root/drivers/iio/inkern.c
diff options
context:
space:
mode:
authorHerve Codina <herve.codina@bootlin.com>2023-06-23 10:58:20 +0200
committerMark Brown <broonie@kernel.org>2023-07-09 22:48:10 +0100
commitf75c544d74133278b004195220f540d8ab953e14 (patch)
tree74f383c19c898fb859c794ab599f7a166778cf9c /drivers/iio/inkern.c
parentb5f3484117b86cb128f500ff2d730c3cfcb9ddfc (diff)
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: Herve Codina <herve.codina@bootlin.com> Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu> Link: https://lore.kernel.org/r/20230623085830.749991-4-herve.codina@bootlin.com Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/iio/inkern.c')
-rw-r--r--drivers/iio/inkern.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index 872fd5c24147..f738db9a0c04 100644
--- a/drivers/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -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;
}
}