]> www.infradead.org Git - users/willy/xarray.git/commitdiff
hwmon: (lm95234) Use find_closest to find matching update interval
authorGuenter Roeck <linux@roeck-us.net>
Wed, 10 Jul 2024 04:23:30 +0000 (21:23 -0700)
committerGuenter Roeck <linux@roeck-us.net>
Wed, 31 Jul 2024 17:43:52 +0000 (10:43 -0700)
Use find_closest() instead of manually coding it to find best update
interval.

Since find_closest() uses rounding to find the best match, the resulting
update interval will now reflect the update interval that is closest to
the requested value, not the value that is lower or equal to the requested
value.

Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/lm95234.c

index 0c509eed6a01265ff220835c53631413f653bb45..a36fa7824da8f7ba4bd47f5ee11c1a12fc392377 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/slab.h>
 #include <linux/mutex.h>
 #include <linux/sysfs.h>
+#include <linux/util_macros.h>
 
 #define DRVNAME "lm95234"
 
@@ -471,10 +472,7 @@ static ssize_t update_interval_store(struct device *dev,
        if (ret < 0)
                return ret;
 
-       for (regval = 0; regval < 3; regval++) {
-               if (val <= update_intervals[regval])
-                       break;
-       }
+       regval = find_closest(val, update_intervals, ARRAY_SIZE(update_intervals));
 
        mutex_lock(&data->update_lock);
        data->interval = msecs_to_jiffies(update_intervals[regval]);