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

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.com


Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent b5f34841
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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;
	}
}