iio: inkern: Check error explicitly in iio_channel_read_max()
authorHerve Codina <herve.codina@bootlin.com>
Fri, 23 Jun 2023 08:58:20 +0000 (10:58 +0200)
committerMark Brown <broonie@kernel.org>
Sun, 9 Jul 2023 21:48:10 +0000 (22:48 +0100)
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>
drivers/iio/inkern.c

index 872fd5c241476eadb4ae4062ac3f59a61a0da970..f738db9a0c04f1b0a6ecfa5f41443e6008049efa 100644 (file)
@@ -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;
        }
 }