From b531d6d44d9b66e4f36d3dd77ce00f96d5e4ad95 Mon Sep 17 00:00:00 2001 From: Philip Elcan Date: Thu, 29 Nov 2018 14:10:01 -0500 Subject: [PATCH] gpu: nvgpu: fix MISRA 10.3 errors in pd_cache MISRA Rule 10.3 prohibits assigning objects to different or narrower types. This change resolves all of the 10.3 violations in the pd_cache unit. JIRA NVGPU-1008 Change-Id: I5b547e0e208caea2e4204708c3a50d98919409f8 Signed-off-by: Philip Elcan Reviewed-on: https://git-master.nvidia.com/r/1962046 Reviewed-by: Adeel Raza Reviewed-by: svc-misra-checker Reviewed-by: svc-mobile-coverity Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: Terje Bergstrom GVS: Gerrit_Virtual_Submit Reviewed-by: Alex Waterman Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/mm/gmmu/pd_cache.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/nvgpu/common/mm/gmmu/pd_cache.c b/drivers/gpu/nvgpu/common/mm/gmmu/pd_cache.c index a14cae4cd..5a18e7cef 100644 --- a/drivers/gpu/nvgpu/common/mm/gmmu/pd_cache.c +++ b/drivers/gpu/nvgpu/common/mm/gmmu/pd_cache.c @@ -149,8 +149,11 @@ struct nvgpu_pd_cache { static u32 nvgpu_pd_cache_nr(u32 bytes) { - return ilog2((unsigned long)bytes >> + unsigned long tmp = ilog2((unsigned long)bytes >> ((unsigned long)NVGPU_PD_CACHE_MIN_SHIFT - 1UL)); + + nvgpu_assert(tmp <= U32_MAX); + return (u32)tmp; } static u32 nvgpu_pd_cache_get_nr_entries(struct nvgpu_pd_mem_entry *pentry) @@ -327,7 +330,8 @@ static int nvgpu_pd_cache_alloc_from_partial(struct gk20a *g, * Find and allocate an open PD. */ bit_offs = find_first_zero_bit(pentry->alloc_map, nr_bits); - mem_offs = bit_offs * pentry->pd_size; + nvgpu_assert(bit_offs <= U32_MAX); + mem_offs = (u32)bit_offs * pentry->pd_size; pd_dbg(g, "PD-Alloc [C] Partial: offs=%lu nr_bits=%d src=0x%p", bit_offs, nr_bits, pentry); @@ -522,7 +526,7 @@ static void nvgpu_pd_cache_free(struct gk20a *g, struct nvgpu_pd_cache *cache, pentry = nvgpu_pd_cache_look_up(g, cache, pd); if (pentry == NULL) { - (void) WARN(1, "Attempting to free non-existent pd"); + (void) WARN(true, "Attempting to free non-existent pd"); return; }