提交 c7c6bf1e 编写于 作者: L Linus Torvalds

Merge tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging

Pull a hwmon fix from Guenter Roeck:
 "One patch, fixing DIV_ROUND_CLOSEST to support negative dividends.

  While the changes are not in the drivers/hwmon directory, the problem
  primarily affects hwmon drivers, and it makes sense to push the patch
  through the hwmon tree."

* tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging:
  linux/kernel.h: Fix DIV_ROUND_CLOSEST to support negative dividends
...@@ -82,10 +82,18 @@ ...@@ -82,10 +82,18 @@
__x - (__x % (y)); \ __x - (__x % (y)); \
} \ } \
) )
/*
* Divide positive or negative dividend by positive divisor and round
* to closest integer. Result is undefined for negative divisors.
*/
#define DIV_ROUND_CLOSEST(x, divisor)( \ #define DIV_ROUND_CLOSEST(x, divisor)( \
{ \ { \
typeof(divisor) __divisor = divisor; \ typeof(x) __x = x; \
(((x) + ((__divisor) / 2)) / (__divisor)); \ typeof(divisor) __d = divisor; \
(((typeof(x))-1) >= 0 || (__x) >= 0) ? \
(((__x) + ((__d) / 2)) / (__d)) : \
(((__x) - ((__d) / 2)) / (__d)); \
} \ } \
) )
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册