iio: inkern: Use max_array() to get the maximum value from an array
authorHerve Codina <herve.codina@bootlin.com>
Fri, 23 Jun 2023 08:58:25 +0000 (10:58 +0200)
committerMark Brown <broonie@kernel.org>
Sun, 9 Jul 2023 21:48:15 +0000 (22:48 +0100)
Use max_array() to get the maximum value from an array instead of a
custom local loop.

Signed-off-by: Herve Codina <herve.codina@bootlin.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Link: https://lore.kernel.org/r/20230623085830.749991-9-herve.codina@bootlin.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/iio/inkern.c

index 71d0424383b611cab47805a38bca05ece3da93c7..8bfd91f74101b45951e57dc70ba236ab41bd1937 100644 (file)
@@ -5,6 +5,7 @@
  */
 #include <linux/err.h>
 #include <linux/export.h>
+#include <linux/minmax.h>
 #include <linux/mutex.h>
 #include <linux/property.h>
 #include <linux/slab.h>
@@ -875,11 +876,7 @@ static int iio_channel_read_max(struct iio_channel *chan,
                        return -EINVAL;
                switch (*type) {
                case IIO_VAL_INT:
-                       *val = vals[--length];
-                       while (length) {
-                               if (vals[--length] > *val)
-                                       *val = vals[length];
-                       }
+                       *val = max_array(vals, length);
                        break;
                default:
                        /* FIXME: learn about max for other iio values */