summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2008-10-17 17:51:14 +0200
committerJean Delvare <khali@mahadeva.delvare>2008-10-17 17:51:14 +0200
commit1b92adaddd7e96e1ba68d4f17a25747ab8057efe (patch)
treeafaf38fe358948d2047264d0708cc2515aa07be7 /drivers/hwmon
parenthwmon: (lm85) Convert to a new-style i2c driver (diff)
downloadlinux-1b92adaddd7e96e1ba68d4f17a25747ab8057efe.tar.xz
linux-1b92adaddd7e96e1ba68d4f17a25747ab8057efe.zip
hwmon: (lm85) Simplify RANGE_TO_REG
Function RANGE_TO_REG can easily be simplified. Credits go to Herbert Poetzl for indirectly suggesting this to me. I tested that the new implementation returns the same result as the original implementation for all input values. Signed-off-by: Jean Delvare <khali@linux-fr.org> Acked-by: Herbert Poetzl <herbert@13thfloor.at>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/lm85.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index 4ee9388df983..94a10ecd24df 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -174,20 +174,13 @@ static int RANGE_TO_REG(int range)
{
int i;
- if (range >= lm85_range_map[15])
- return 15;
-
/* Find the closest match */
- for (i = 14; i >= 0; --i) {
- if (range >= lm85_range_map[i]) {
- if ((lm85_range_map[i + 1] - range) <
- (range - lm85_range_map[i]))
- return i + 1;
- return i;
- }
+ for (i = 0; i < 15; ++i) {
+ if (range <= (lm85_range_map[i] + lm85_range_map[i + 1]) / 2)
+ break;
}
- return 0;
+ return i;
}
#define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f]