Merge tag 'pci-v4.4-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci
[firefly-linux-kernel-4.4.55.git] / drivers / hwmon / w83795.c
index 21894131190f4b9a3d18f29e619f352d9fcdb279..49276bbdac3ddf0dc1153cb1941cf28f0ac10ea7 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/err.h>
 #include <linux/mutex.h>
 #include <linux/jiffies.h>
+#include <linux/util_macros.h>
 
 /* Addresses to scan */
 static const unsigned short normal_i2c[] = {
@@ -308,11 +309,8 @@ static u8 pwm_freq_to_reg(unsigned long val, u16 clkin)
        unsigned long best0, best1;
 
        /* Best fit for cksel = 0 */
-       for (reg0 = 0; reg0 < ARRAY_SIZE(pwm_freq_cksel0) - 1; reg0++) {
-               if (val > (pwm_freq_cksel0[reg0] +
-                          pwm_freq_cksel0[reg0 + 1]) / 2)
-                       break;
-       }
+       reg0 = find_closest_descending(val, pwm_freq_cksel0,
+                                      ARRAY_SIZE(pwm_freq_cksel0));
        if (val < 375)  /* cksel = 1 can't beat this */
                return reg0;
        best0 = pwm_freq_cksel0[reg0];