The patch titled Subject: linux/kernel.h: fix DIV_ROUND_CLOSEST to support negative divisors has been added to the -mm tree. Its filename is linux-kernelh-fix-div_round_closest-to-support-negative-divisors.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/linux-kernelh-fix-div_round_closest-to-support-negative-divisors.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/linux-kernelh-fix-div_round_closest-to-support-negative-divisors.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Niklas Söderlund <niklas.soderlund+renesas@xxxxxxxxxxxx> Subject: linux/kernel.h: fix DIV_ROUND_CLOSEST to support negative divisors While working on a thermal driver I encounter a scenario where the divisor could be negative, instead of adding local code to handle this I though I first try to add support for this in DIV_ROUND_CLOSEST. Add support to DIV_ROUND_CLOSEST for negative divisors if both dividend and divisor variable types are signed. This should not alter current behavior for users of the macro as previously negative divisors where not supported. Before: DIV_ROUND_CLOSEST( 59, 4) = 15 DIV_ROUND_CLOSEST( 59, -4) = -14 DIV_ROUND_CLOSEST( -59, 4) = -15 DIV_ROUND_CLOSEST( -59, -4) = 14 After: DIV_ROUND_CLOSEST( 59, 4) = 15 DIV_ROUND_CLOSEST( 59, -4) = -15 DIV_ROUND_CLOSEST( -59, 4) = -15 DIV_ROUND_CLOSEST( -59, -4) = 15 Link: http://lkml.kernel.org/r/20161222102217.29011-1-niklas.soderlund+renesas@xxxxxxxxxxxx Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@xxxxxxxxxxxx> Reviewed-by: Guenter Roeck <linux@xxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/kernel.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff -puN include/linux/kernel.h~linux-kernelh-fix-div_round_closest-to-support-negative-divisors include/linux/kernel.h --- a/include/linux/kernel.h~linux-kernelh-fix-div_round_closest-to-support-negative-divisors +++ a/include/linux/kernel.h @@ -100,16 +100,18 @@ ) /* - * Divide positive or negative dividend by positive divisor and round - * to closest integer. Result is undefined for negative divisors and - * for negative dividends if the divisor variable type is unsigned. + * Divide positive or negative dividend by positive or negative divisor + * and round to closest integer. Result is undefined for negative + * divisors if dividends variable type is unsigned and for negative + * dividends if the divisor variable type is unsigned. */ #define DIV_ROUND_CLOSEST(x, divisor)( \ { \ typeof(x) __x = x; \ typeof(divisor) __d = divisor; \ (((typeof(x))-1) > 0 || \ - ((typeof(divisor))-1) > 0 || (__x) > 0) ? \ + ((typeof(divisor))-1) > 0 || \ + (((__x) > 0) == ((__d) > 0))) ? \ (((__x) + ((__d) / 2)) / (__d)) : \ (((__x) - ((__d) / 2)) / (__d)); \ } \ _ Patches currently in -mm which might be from niklas.soderlund+renesas@xxxxxxxxxxxx are linux-kernelh-fix-div_round_closest-to-support-negative-divisors.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html