summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2024-07-09 21:23:30 -0700
committerGuenter Roeck <linux@roeck-us.net>2024-07-31 10:43:52 -0700
commite38b05f0a2fd5b92341d366c9f4f74301cd41ac6 (patch)
treea383966716421a11d4da129d5b542d082d90c92c
parent8abff91c6173b175bda3381bdb14981249502434 (diff)
downloadlinux-e38b05f0a2fd5b92341d366c9f4f74301cd41ac6.tar.gz
linux-e38b05f0a2fd5b92341d366c9f4f74301cd41ac6.tar.bz2
linux-e38b05f0a2fd5b92341d366c9f4f74301cd41ac6.zip
hwmon: (lm95234) Use find_closest to find matching update interval
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>
-rw-r--r--drivers/hwmon/lm95234.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/drivers/hwmon/lm95234.c b/drivers/hwmon/lm95234.c
index 0c509eed6a01..a36fa7824da8 100644
--- a/drivers/hwmon/lm95234.c
+++ b/drivers/hwmon/lm95234.c
@@ -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]);