From 38cc3ed48f11d2953b6a8b81239da4c858cbfa5e Mon Sep 17 00:00:00 2001 From: Vedashree Vidwans Date: Thu, 3 Oct 2019 11:28:28 -0700 Subject: [PATCH] gpu: nvgpu: fix CERT-C violations in mm INT30-C requires that unsigned integer operations do not wrap. Jira NVGPU-3882 Change-Id: I2424416e79d4203931fd28afc1c9349a746d8f68 Signed-off-by: Vedashree Vidwans Reviewed-on: https://git-master.nvidia.com/r/2211033 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-misra Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Adeel Raza Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/mm/allocators/bitmap_allocator.c | 2 +- drivers/gpu/nvgpu/common/mm/allocators/buddy_allocator.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/nvgpu/common/mm/allocators/bitmap_allocator.c b/drivers/gpu/nvgpu/common/mm/allocators/bitmap_allocator.c index 0379d588d..7c1860cbc 100644 --- a/drivers/gpu/nvgpu/common/mm/allocators/bitmap_allocator.c +++ b/drivers/gpu/nvgpu/common/mm/allocators/bitmap_allocator.c @@ -442,7 +442,7 @@ int nvgpu_bitmap_allocator_init(struct gk20a *g, struct nvgpu_allocator *na, if (base == 0ULL) { base = blk_size; - length -= blk_size; + length = nvgpu_safe_sub_u64(length, blk_size); } a = nvgpu_kzalloc(g, sizeof(struct nvgpu_bitmap_allocator)); diff --git a/drivers/gpu/nvgpu/common/mm/allocators/buddy_allocator.c b/drivers/gpu/nvgpu/common/mm/allocators/buddy_allocator.c index e0fc4fc21..c18fdcbf1 100644 --- a/drivers/gpu/nvgpu/common/mm/allocators/buddy_allocator.c +++ b/drivers/gpu/nvgpu/common/mm/allocators/buddy_allocator.c @@ -1393,7 +1393,7 @@ static int nvgpu_buddy_set_attributes(struct nvgpu_buddy_allocator *a, a->base = base; a->length = size; a->blk_size = blk_size; - a->blk_shift = (nvgpu_ffs(blk_size) - 1UL); + a->blk_shift = nvgpu_safe_sub_u64(nvgpu_ffs(blk_size), 1UL); a->owner = na; /* @@ -1402,7 +1402,7 @@ static int nvgpu_buddy_set_attributes(struct nvgpu_buddy_allocator *a, */ if (a->base == 0U) { a->base = a->blk_size; - a->length -= a->blk_size; + a->length = nvgpu_safe_sub_u64(a->length, a->blk_size); } a->vm = vm;