From e946c2cbccdc74ad885e98b2e4a1a30177b6e22a Mon Sep 17 00:00:00 2001 From: chandra Date: Tue, 3 Dec 2024 11:38:06 +0000 Subject: [PATCH] nvscic2c-pcie: Fix Top25 CWE CERT-C violations Fix total 20 violations of rule CERT-C EXP34-C JIRA NVIPC-3120 Change-Id: I1e8940269a2859a0483215cf44170dd669f637ea Signed-off-by: chandra Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3260920 Reviewed-by: Janardhan Reddy AnnapuReddy Reviewed-by: svcacv GVS: buildbot_gerritrpt Reviewed-by: Sumeet Gupta --- drivers/misc/nvscic2c-pcie/comm-channel.c | 11 ++++- drivers/misc/nvscic2c-pcie/endpoint.c | 6 ++- .../misc/nvscic2c-pcie/stream-extensions.c | 40 +++++++++++++++---- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/drivers/misc/nvscic2c-pcie/comm-channel.c b/drivers/misc/nvscic2c-pcie/comm-channel.c index 45977929..2b52688c 100644 --- a/drivers/misc/nvscic2c-pcie/comm-channel.c +++ b/drivers/misc/nvscic2c-pcie/comm-channel.c @@ -1,5 +1,8 @@ // SPDX-License-Identifier: GPL-2.0-only -// Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +/* + * SPDX-FileCopyrightText: Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. + * All rights reserved. + */ #define pr_fmt(fmt) "nvscic2c-pcie: comm-channel: " fmt @@ -375,7 +378,11 @@ allocate_fence(struct syncpt_t *syncpt) int ret = 0; struct dma_fence *fence = NULL; - fence = host1x_fence_create(syncpt->sp, ++syncpt->threshold, false); + if (syncpt->threshold == U32_MAX) + syncpt->threshold = 0; + else + ++syncpt->threshold; + fence = host1x_fence_create(syncpt->sp, syncpt->threshold, false); if (IS_ERR_OR_NULL(fence)) { ret = PTR_ERR(fence); pr_err("host1x_fence_create failed with: %d\n", ret); diff --git a/drivers/misc/nvscic2c-pcie/endpoint.c b/drivers/misc/nvscic2c-pcie/endpoint.c index dd6f12a0..f7374f04 100644 --- a/drivers/misc/nvscic2c-pcie/endpoint.c +++ b/drivers/misc/nvscic2c-pcie/endpoint.c @@ -589,7 +589,11 @@ allocate_fence(struct syncpt_t *syncpt) int ret = 0; struct dma_fence *fence = NULL; - fence = host1x_fence_create(syncpt->sp, ++syncpt->threshold, false); + if (syncpt->threshold == U32_MAX) + syncpt->threshold = 0; + else + ++syncpt->threshold; + fence = host1x_fence_create(syncpt->sp, syncpt->threshold, false); if (IS_ERR(fence)) { ret = PTR_ERR(fence); pr_err("host1x_fence_create failed with: %d\n", ret); diff --git a/drivers/misc/nvscic2c-pcie/stream-extensions.c b/drivers/misc/nvscic2c-pcie/stream-extensions.c index c263f258..258e8e58 100644 --- a/drivers/misc/nvscic2c-pcie/stream-extensions.c +++ b/drivers/misc/nvscic2c-pcie/stream-extensions.c @@ -1030,7 +1030,10 @@ prepare_edma_desc(enum drv_mode_t drv_mode, struct copy_req_params *params, fput(filep); desc[iter].sz = flush_range->size; - iter++; + if (iter == U32_MAX) + iter = 0; + else + iter++; } *num_desc += iter; return ret; @@ -1127,10 +1130,16 @@ cache_copy_request_handles(struct copy_req_params *params, stream_obj = filep->private_data; kref_get(&stream_obj->refcount); cr->handles[cr->num_handles] = stream_obj; - cr->num_handles++; + if (cr->num_handles == U64_MAX) + cr->num_handles = 0; + else + cr->num_handles++; /* collect all local post fences separately for nvhost incr.*/ cr->local_post_fences[cr->num_local_post_fences] = stream_obj; - cr->num_local_post_fences++; + if (cr->num_local_post_fences == U64_MAX) + cr->num_local_post_fences = 0; + else + cr->num_local_post_fences++; fput(filep); } for (i = 0; i < params->num_remote_post_fences; i++) { @@ -1139,10 +1148,16 @@ cache_copy_request_handles(struct copy_req_params *params, stream_obj = filep->private_data; kref_get(&stream_obj->refcount); cr->handles[cr->num_handles] = stream_obj; - cr->num_handles++; + if (cr->num_handles == U64_MAX) + cr->num_handles = 0; + else + cr->num_handles++; cr->remote_post_fence_values[i] = params->remote_post_fence_values[i]; cr->remote_post_fences[cr->num_remote_post_fences] = stream_obj; - cr->num_remote_post_fences++; + if (cr->num_remote_post_fences == U64_MAX) + cr->num_remote_post_fences = 0; + else + cr->num_remote_post_fences++; fput(filep); } for (i = 0; i < params->num_flush_ranges; i++) { @@ -1151,7 +1166,10 @@ cache_copy_request_handles(struct copy_req_params *params, stream_obj = filep->private_data; kref_get(&stream_obj->refcount); cr->handles[cr->num_handles] = stream_obj; - cr->num_handles++; + if (cr->num_handles == U64_MAX) + cr->num_handles = 0; + else + cr->num_handles++; fput(filep); handle = params->flush_ranges[i].dst_handle; @@ -1159,10 +1177,16 @@ cache_copy_request_handles(struct copy_req_params *params, stream_obj = filep->private_data; kref_get(&stream_obj->refcount); cr->handles[cr->num_handles] = stream_obj; - cr->num_handles++; + if (cr->num_handles == U64_MAX) + cr->num_handles = 0; + else + cr->num_handles++; cr->remote_buf_objs[cr->num_remote_buf_objs] = stream_obj; - cr->num_remote_buf_objs++; + if (cr->num_remote_buf_objs == U64_MAX) + cr->num_remote_buf_objs = 0; + else + cr->num_remote_buf_objs++; fput(filep); }