From 345ffb47e4cb20b14cfa29ec85d9004a780934f5 Mon Sep 17 00:00:00 2001 From: Philip Elcan Date: Thu, 1 Aug 2019 17:27:21 -0400 Subject: [PATCH] gpu: nvgpu: netlist: fix CERT-C violations CERT-C Rule INT30-C Requires that unsigned integer operations do not wrap. Fix these violations by using the safe ops. JIRA NVGPU-3868 Change-Id: Ic1a4c19e565a061302b681b191318c6aede8e676 Signed-off-by: Philip Elcan Reviewed-on: https://git-master.nvidia.com/r/2168574 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-misra Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Vinod Gopalakrishnakurup Reviewed-by: Nitin Kumbhar Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/netlist/netlist.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/nvgpu/common/netlist/netlist.c b/drivers/gpu/nvgpu/common/netlist/netlist.c index f1d13a072..027bae385 100644 --- a/drivers/gpu/nvgpu/common/netlist/netlist.c +++ b/drivers/gpu/nvgpu/common/netlist/netlist.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "netlist_priv.h" #include "netlist_defs.h" @@ -49,35 +50,41 @@ struct netlist_av *nvgpu_netlist_alloc_av_list(struct gk20a *g, struct netlist_av_list *avl) { - avl->l = nvgpu_kzalloc(g, avl->count * sizeof(*avl->l)); + avl->l = nvgpu_kzalloc(g, nvgpu_safe_mult_u64(avl->count, + sizeof(*avl->l))); return avl->l; } struct netlist_av64 *nvgpu_netlist_alloc_av64_list(struct gk20a *g, struct netlist_av64_list *avl) { - avl->l = nvgpu_kzalloc(g, avl->count * sizeof(*avl->l)); + avl->l = nvgpu_kzalloc(g, nvgpu_safe_mult_u64(avl->count, + sizeof(*avl->l))); return avl->l; } struct netlist_aiv *nvgpu_netlist_alloc_aiv_list(struct gk20a *g, struct netlist_aiv_list *aivl) { - aivl->l = nvgpu_kzalloc(g, aivl->count * sizeof(*aivl->l)); + aivl->l = nvgpu_kzalloc(g, nvgpu_safe_mult_u64(aivl->count, + sizeof(*aivl->l))); return aivl->l; } u32 *nvgpu_netlist_alloc_u32_list(struct gk20a *g, struct netlist_u32_list *u32l) { - u32l->l = nvgpu_kzalloc(g, u32l->count * sizeof(*u32l->l)); + u32l->l = nvgpu_kzalloc(g, nvgpu_safe_mult_u64(u32l->count, + sizeof(*u32l->l))); return u32l->l; } static int nvgpu_netlist_alloc_load_u32_list(struct gk20a *g, u8 *src, u32 len, struct netlist_u32_list *u32_list) { - u32_list->count = (len + U32(sizeof(u32)) - 1U) / U32(sizeof(u32)); + u32_list->count = nvgpu_safe_add_u32(len, + nvgpu_safe_cast_u64_to_u32(sizeof(u32) - 1UL)) + / U32(sizeof(u32)); if (nvgpu_netlist_alloc_u32_list(g, u32_list) == NULL) { return -ENOMEM; }