Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (w83795) use find_closest_descending() in pwm_freq_to_reg()

Replace the loop iterating over pwm_freq_cksel0 with a call to
find_closest_descending().

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Bartosz Golaszewski and committed by
Linus Torvalds
cdb1dc3f 0f3721c5

+3 -5
+3 -5
drivers/hwmon/w83795.c
··· 35 35 #include <linux/err.h> 36 36 #include <linux/mutex.h> 37 37 #include <linux/jiffies.h> 38 + #include <linux/util_macros.h> 38 39 39 40 /* Addresses to scan */ 40 41 static const unsigned short normal_i2c[] = { ··· 309 308 unsigned long best0, best1; 310 309 311 310 /* Best fit for cksel = 0 */ 312 - for (reg0 = 0; reg0 < ARRAY_SIZE(pwm_freq_cksel0) - 1; reg0++) { 313 - if (val > (pwm_freq_cksel0[reg0] + 314 - pwm_freq_cksel0[reg0 + 1]) / 2) 315 - break; 316 - } 311 + reg0 = find_closest_descending(val, pwm_freq_cksel0, 312 + ARRAY_SIZE(pwm_freq_cksel0)); 317 313 if (val < 375) /* cksel = 1 can't beat this */ 318 314 return reg0; 319 315 best0 = pwm_freq_cksel0[reg0];