From 9c40a7389dd0fcfdf5b490fec9a240ec47d173a4 Mon Sep 17 00:00:00 2001 From: ajesh Date: Thu, 23 Jan 2020 16:03:56 +0530 Subject: [PATCH] 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 Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2284320 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: Alex Waterman Reviewed-by: mobile promotions Tested-by: mobile promotions GVS: Gerrit_Virtual_Submit --- drivers/gpu/nvgpu/include/nvgpu/posix/utils.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/utils.h b/drivers/gpu/nvgpu/include/nvgpu/posix/utils.h index d5b07ec15..49300fca7 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/posix/utils.h +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/utils.h @@ -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)); \ } \