aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lm85.c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2008-10-17 11:51:14 -0400
committerJean Delvare <khali@mahadeva.delvare>2008-10-17 11:51:14 -0400
commit1b92adaddd7e96e1ba68d4f17a25747ab8057efe (patch)
treeafaf38fe358948d2047264d0708cc2515aa07be7 /drivers/hwmon/lm85.c
parent67712d01929295112b55fedd0b3c13f7d5c34f98 (diff)
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/lm85.c')
-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)
174{ 174{
175 int i; 175 int i;
176 176
177 if (range >= lm85_range_map[15])
178 return 15;
179
180 /* Find the closest match */ 177 /* Find the closest match */
181 for (i = 14; i >= 0; --i) { 178 for (i = 0; i < 15; ++i) {
182 if (range >= lm85_range_map[i]) { 179 if (range <= (lm85_range_map[i] + lm85_range_map[i + 1]) / 2)
183 if ((lm85_range_map[i + 1] - range) < 180 break;
184 (range - lm85_range_map[i]))
185 return i + 1;
186 return i;
187 }
188 } 181 }
189 182
190 return 0; 183 return i;
191} 184}
192#define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f] 185#define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f]
193 186