提交 1b92adad 编写于 作者: J Jean Delvare 提交者: Jean Delvare

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: NJean Delvare <khali@linux-fr.org>
Acked-by: NHerbert Poetzl <herbert@13thfloor.at>
上级 67712d01
......@@ -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]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册