From 1551e7ea3df3dc8c45633b4b93f5d5b3badeec4a Mon Sep 17 00:00:00 2001 From: Philip Elcan Date: Fri, 19 Jul 2019 14:27:32 -0400 Subject: [PATCH] gpu: nvgpu: init: fix CERT-C violations CERT-C INT-30 requires checking if arithmetic operations will wrap. Use the safe ops in hal_init.c to avoid this violation JIRA NVGPU-3847 Change-Id: If6616f7ff9133f652c11325ae04fc7842a0b97a3 Signed-off-by: Philip Elcan Reviewed-on: https://git-master.nvidia.com/r/2157278 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/hal/init/hal_init.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/nvgpu/hal/init/hal_init.c b/drivers/gpu/nvgpu/hal/init/hal_init.c index a8708614e..4795ff00b 100644 --- a/drivers/gpu/nvgpu/hal/init/hal_init.c +++ b/drivers/gpu/nvgpu/hal/init/hal_init.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "hal_gm20b.h" #include "hal_gp10b.h" @@ -38,7 +39,7 @@ int nvgpu_init_hal(struct gk20a *g) { int err = 0; - u32 ver = g->params.gpu_arch + g->params.gpu_impl; + u32 ver = nvgpu_safe_add_u32(g->params.gpu_arch, g->params.gpu_impl); switch (ver) { #ifdef CONFIG_NVGPU_HAL_NON_FUSA @@ -102,7 +103,8 @@ int nvgpu_detect_chip(struct gk20a *g) return -ENODEV; } - if ((p->gpu_arch + p->gpu_impl) == (u32)NVGPU_GPUID_GV11B) { + if (nvgpu_safe_add_u32(p->gpu_arch, p->gpu_impl) == + (u32)NVGPU_GPUID_GV11B) { /* overwrite gpu revison for A02 */ if (!nvgpu_is_soc_t194_a01(g)) { p->gpu_rev = 0xa2;