gpu: nvgpu: mm: use constants for string lengths

For VM and allocator names, hardcoded constants were used which
can be a weakness. This patch uses proper defines in headers
instead.

JIRA NVGPU-4946

Change-Id: I1cc100a558d0c44c208a7e579cc36b71a0d4eeec
Signed-off-by: Nicolas Benech <nbenech@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2291069
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svc-mobile-cert <svc-mobile-cert@nvidia.com>
Reviewed-by: Deepak Nibade <dnibade@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
GVS: Gerrit_Virtual_Submit
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Nicolas Benech
2020-02-06 12:38:50 -05:00
committed by Alex Waterman
parent e8c02f121b
commit 30755fef04
4 changed files with 16 additions and 4 deletions

View File

@@ -56,7 +56,7 @@ static int gk20a_vm_alloc_share(struct gk20a_as_share *as_share,
struct gk20a *g = gk20a_from_as(as);
struct mm_gk20a *mm = &g->mm;
struct vm_gk20a *vm;
char name[32];
char name[NVGPU_VM_NAME_LEN];
char *p;
const bool userspace_managed =
(flags & NVGPU_AS_ALLOC_USERSPACE_MANAGED) != 0U;

View File

@@ -398,7 +398,15 @@ static int nvgpu_vm_init_user_vma(struct gk20a *g, struct vm_gk20a *vm,
const char *name)
{
int err = 0;
char alloc_name[32];
char alloc_name[NVGPU_ALLOC_NAME_LEN];
size_t name_len;
name_len = strlen("gk20a_") + strlen(name);
if (name_len >= NVGPU_ALLOC_NAME_LEN) {
nvgpu_err(g, "Invalid MAX_NAME_SIZE %lu %u", name_len,
NVGPU_ALLOC_NAME_LEN);
return -EINVAL;
}
/*
* User VMA.

View File

@@ -57,6 +57,8 @@ struct nvgpu_alloc_carveout;
struct vm_gk20a;
struct gk20a;
#define NVGPU_ALLOC_NAME_LEN 32U
/**
* Structure containing operations for an allocator to implement.
*/
@@ -217,7 +219,7 @@ struct nvgpu_allocator {
/**
* Name of allocator.
*/
char name[32];
char name[NVGPU_ALLOC_NAME_LEN];
/**
* Synchronization mutex.
*/

View File

@@ -97,6 +97,8 @@ struct nvgpu_os_buffer;
#include <nvgpu_rmos/include/vm.h>
#endif
#define NVGPU_VM_NAME_LEN 20U
/**
* This structure describes the properties of batch mapping/unmapping.
*/
@@ -222,7 +224,7 @@ struct vm_gk20a {
*/
struct gk20a_as_share *as_share;
/** Name of the Virtual Memory context. */
char name[20];
char name[NVGPU_VM_NAME_LEN];
/** Start GPU address of the context. */
u64 va_start;