From 16b80d2c5ca8df65842cb8f426e0bcd778cea046 Mon Sep 17 00:00:00 2001 From: Nicolas Benech Date: Thu, 6 Feb 2020 10:39:50 -0500 Subject: [PATCH] gpu: nvgpu: pd_cache: add BUG_ON to guard divide by 0 In the unlikely event of a corruption of pentry->pd_size this new BUG_ON prevents a potential divide by 0. This change is mostly to increase safety as it is unlikely for a divide by 0 to occur in this instance. JIRA NVGPU-4949 Change-Id: Ibdf80670f35a63dd20d06082cde23fb424931933 Signed-off-by: Nicolas Benech Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2291022 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-misra Reviewed-by: svc-mobile-cert Reviewed-by: Deepak Nibade Reviewed-by: mobile promotions GVS: Gerrit_Virtual_Submit Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/mm/gmmu/pd_cache.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/nvgpu/common/mm/gmmu/pd_cache.c b/drivers/gpu/nvgpu/common/mm/gmmu/pd_cache.c index 4e41f34f0..f1681a3d6 100644 --- a/drivers/gpu/nvgpu/common/mm/gmmu/pd_cache.c +++ b/drivers/gpu/nvgpu/common/mm/gmmu/pd_cache.c @@ -60,6 +60,8 @@ static u32 nvgpu_pd_cache_nr(u32 bytes) static u32 nvgpu_pd_cache_get_nr_entries(struct nvgpu_pd_mem_entry *pentry) { + BUG_ON(pentry->pd_size == 0); + return PAGE_SIZE / pentry->pd_size; }