gpu: nvgpu: fix issue with DIV_ROUND_CLOSEST

Fix the issue in DIV_ROUND_CLOSEST implementation. Current
implementation will have issues for an input of two negative
numbers. For example, Input values of a = -13 and divisor = -5
should ideally give result as 3. But because of the third condition
check ie.(val) > 0, the result would be given incorrectly as 2
with the current implementation. Modify the condition to handle
two negative number division.

Jira NVGPU-4478

Change-Id: Ifb3f58b4ff742abbb59fda328c1b5facdcb1b38b
Signed-off-by: ajesh <akv@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2284320
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Alex Waterman <alexw@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
GVS: Gerrit_Virtual_Submit
This commit is contained in:
ajesh
2020-01-23 16:03:56 +05:30
committed by Alex Waterman
parent 30dd0732bf
commit 9c40a7389d

View File

@@ -146,7 +146,8 @@
typeof(a) val = (a); \
typeof(divisor) div = (divisor); \
(((typeof(a))-1) > 0 || \
((typeof(divisor))-1) > 0 || (val) > 0) ? \
((typeof(divisor))-1) > 0 || \
(((val) > 0) == ((div) > 0))) ? \
(((val) + ((div) / 2)) / (div)) : \
(((val) - ((div) / 2)) / (div)); \
} \