gpu: nvgpu: fbp: 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: I79abc966425dc454f0fbcaca24506c73b63ff683
Signed-off-by: Philip Elcan <pelcan@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/2166260
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svc-mobile-misra <svc-mobile-misra@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Nitin Kumbhar <nkumbhar@nvidia.com>
Reviewed-by: Alex Waterman <alexw@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Philip Elcan
2019-08-01 15:08:02 -04:00
committed by mobile promotions
parent 42f5a2d806
commit 2eb3ba4fa2

View File

@@ -24,6 +24,7 @@
#include <nvgpu/kmem.h>
#include <nvgpu/log.h>
#include <nvgpu/fbp.h>
#include <nvgpu/safe_ops.h>
#include "fbp_priv.h"
@@ -60,11 +61,13 @@ int nvgpu_fbp_init_support(struct gk20a *g)
*/
fbp_en_mask = g->ops.fuse.fuse_status_opt_fbp(g);
fbp_en_mask = ~fbp_en_mask;
fbp_en_mask = fbp_en_mask & (BIT32(fbp->max_fbps_count) - 1U);
fbp_en_mask = fbp_en_mask &
nvgpu_safe_sub_u32(BIT32(fbp->max_fbps_count), 1U);
fbp->fbp_en_mask = fbp_en_mask;
fbp->fbp_rop_l2_en_mask =
nvgpu_kzalloc(g, fbp->max_fbps_count * sizeof(u32));
nvgpu_kzalloc(g,
nvgpu_safe_mult_u64(fbp->max_fbps_count, sizeof(u32)));
if (fbp->fbp_rop_l2_en_mask == NULL) {
nvgpu_kfree(g, fbp);
return -ENOMEM;
@@ -72,7 +75,7 @@ int nvgpu_fbp_init_support(struct gk20a *g)
fbp_en_mask_tmp = fbp_en_mask;
max_ltc_per_fbp = g->ops.top.get_max_ltc_per_fbp(g);
rop_l2_all_en = BIT32(max_ltc_per_fbp) - 1U;
rop_l2_all_en = nvgpu_safe_sub_u32(BIT32(max_ltc_per_fbp), 1U);
/* mask of Rop_L2 for each FBP */
for_each_set_bit(i, &fbp_en_mask_tmp, fbp->max_fbps_count) {