From: Bartosz Golaszewski Date: Thu, 16 Apr 2015 19:43:39 +0000 (-0700) Subject: hwmon: (w83795) use find_closest_descending() in pwm_freq_to_reg() X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=cdb1dc3f1ca5c5899e5fa186afe20390bd8c00dc;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git 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 Cc: Guenter Roeck Cc: Steven Rostedt Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c index 21894131190f..49276bbdac3d 100644 --- a/drivers/hwmon/w83795.c +++ b/drivers/hwmon/w83795.c @@ -35,6 +35,7 @@ #include #include #include +#include /* 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];