From: Herve Codina Date: Fri, 23 Jun 2023 08:58:20 +0000 (+0200) Subject: iio: inkern: Check error explicitly in iio_channel_read_max() X-Git-Tag: 6.6-rc-smb3-client-fixes-part2~25^2~3^2~217^2~10 X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=f75c544d74133278b004195220f540d8ab953e14;p=sfrench%2Fcifs-2.6.git 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 Acked-by: Jonathan Cameron Reviewed-by: Andy Shevchenko Reviewed-by: Christophe Leroy Link: https://lore.kernel.org/r/20230623085830.749991-4-herve.codina@bootlin.com Signed-off-by: Mark Brown --- 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; } }