gpu: nvgpu: Fix boardobj allocation size

In current implementation we are allocating boardobj
in nvgpu_boardobj_construct_super for all units and assigning
that pointer to boardobj type, as the size differe for different
units assigning the boardobj pointer to a common type will
give violations. Fixing them by allocating mem a head
and later call construct_super for elements initialization.

NVGPU-4484

Change-Id: I9b5ed1a6d8418fec48a29eee38d55fc7d83fcfab
Signed-off-by: rmylavarapu <rmylavarapu@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2335989
Reviewed-by: automaticguardword <automaticguardword@nvidia.com>
Reviewed-by: Mahantesh Kumbar <mkumbar@nvidia.com>
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svc-mobile-misra <svc-mobile-misra@nvidia.com>
Reviewed-by: svc-mobile-cert <svc-mobile-cert@nvidia.com>
Reviewed-by: Vaibhav Kachore <vkachore@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
GVS: Gerrit_Virtual_Submit
This commit is contained in:
rmylavarapu
2020-04-29 12:00:28 +05:30
committed by Alex Waterman
parent 0115c26f1b
commit 8e545ef04b
18 changed files with 165 additions and 83 deletions

View File

@@ -75,39 +75,29 @@ int nvgpu_boardobj_pmu_data_init_super(struct gk20a *g,
return 0;
}
int nvgpu_boardobj_construct_super(struct gk20a *g, struct boardobj
**ppboardobj, size_t size, void *args)
int pmu_boardobj_construct_super(struct gk20a *g, struct boardobj *boardobj_ptr,
void *args)
{
struct boardobj *pboardobj = NULL;
struct boardobj *devtmp = (struct boardobj *)args;
struct boardobj *dev_boardobj = (struct boardobj *)args;
nvgpu_log_info(g, " ");
if (devtmp == NULL) {
if ((dev_boardobj == NULL) || (boardobj_ptr == NULL)) {
return -EINVAL;
}
if (*ppboardobj == NULL) {
*ppboardobj = nvgpu_kzalloc(g, size);
if (*ppboardobj == NULL) {
return -ENOMEM;
}
(*ppboardobj)->allocated = true;
}
boardobj_ptr->allocated = true;
boardobj_ptr->g = g;
boardobj_ptr->type = dev_boardobj->type;
boardobj_ptr->idx = CTRL_BOARDOBJ_IDX_INVALID;
boardobj_ptr->type_mask =
BIT32(boardobj_ptr->type) | dev_boardobj->type_mask;
pboardobj = *ppboardobj;
pboardobj->g = g;
pboardobj->type = devtmp->type;
pboardobj->idx = CTRL_BOARDOBJ_IDX_INVALID;
pboardobj->type_mask = BIT32(pboardobj->type) | devtmp->type_mask;
pboardobj->implements = implements_super;
pboardobj->destruct = destruct_super;
pboardobj->pmudatainit = nvgpu_boardobj_pmu_data_init_super;
nvgpu_list_add(&pboardobj->node, &g->boardobj_head);
boardobj_ptr->implements = implements_super;
boardobj_ptr->destruct = destruct_super;
boardobj_ptr->pmudatainit = nvgpu_boardobj_pmu_data_init_super;
nvgpu_list_add(&boardobj_ptr->node, &g->boardobj_head);
return 0;
}

View File

@@ -40,8 +40,8 @@ int nvgpu_boardobj_pmu_data_init_super(struct gk20a *g, struct boardobj
* Constructor for the base Board Object. Called by each device-specific
* implementation of the BOARDOBJ interface to initialize the board object.
*/
int nvgpu_boardobj_construct_super(struct gk20a *g, struct boardobj
**ppboardobj, size_t size, void *args);
int pmu_boardobj_construct_super(struct gk20a *g, struct boardobj *ppboardobj,
void *args);
/*
* Base Class for all physical or logical device on the PCB.

View File

@@ -655,14 +655,19 @@ static int clk_domain_construct_super(struct gk20a *g,
struct nvgpu_clk_domain *ptmpdomain = (struct nvgpu_clk_domain *)pargs;
int status = 0;
status = nvgpu_boardobj_construct_super(g, ppboardobj,
(u16)size, pargs);
pdomain = nvgpu_kzalloc(g, size);
if (pdomain == NULL) {
return -ENOMEM;
}
status = pmu_boardobj_construct_super(g,
(struct boardobj *)(void *)pdomain, pargs);
if (status != 0) {
return -EINVAL;
}
pdomain = (struct nvgpu_clk_domain *)(void *)*ppboardobj;
*ppboardobj = (struct boardobj *)(void *)pdomain;
pdomain->super.pmudatainit =
clk_domain_pmudatainit_super;

View File

@@ -448,14 +448,19 @@ static struct fll_device *construct_fll_device(struct gk20a *g,
int status;
nvgpu_log_info(g, " ");
status = nvgpu_boardobj_construct_super(g, &board_obj_ptr,
sizeof(struct fll_device), pargs);
board_obj_fll_ptr = nvgpu_kzalloc(g, sizeof(struct fll_device));
if (board_obj_fll_ptr == NULL) {
return NULL;
}
board_obj_ptr = (struct boardobj *)(void *)board_obj_fll_ptr;
status = pmu_boardobj_construct_super(g, board_obj_ptr, pargs);
if (status != 0) {
return NULL;
}
pfll_dev = (struct fll_device *)pargs;
board_obj_fll_ptr = (struct fll_device *)board_obj_ptr;
board_obj_ptr->pmudatainit = fll_device_init_pmudata_super;
board_obj_fll_ptr->lut_broadcast_slave_register =
lutbroadcastslaveregister;

View File

@@ -674,13 +674,18 @@ static int clk_prog_construct_super(struct gk20a *g,
struct clk_prog *pclkprog;
int status = 0;
status = nvgpu_boardobj_construct_super(g, ppboardobj,
size, pargs);
pclkprog = nvgpu_kzalloc(g, size);
if (pclkprog == NULL) {
return -ENOMEM;
}
status = pmu_boardobj_construct_super(g,
(struct boardobj *)(void *)pclkprog, pargs);
if (status != 0) {
return -EINVAL;
}
pclkprog = (struct clk_prog *)(void *)*ppboardobj;
*ppboardobj = (struct boardobj *)(void *)pclkprog;
pclkprog->super.pmudatainit =
clk_prog_pmudatainit_super;

View File

@@ -197,13 +197,18 @@ static int clk_vf_point_construct_super(struct gk20a *g,
(struct clk_vf_point *)pargs;
int status = 0;
status = nvgpu_boardobj_construct_super(g, ppboardobj,
size, pargs);
pclkvfpoint = nvgpu_kzalloc(g, size);
if (pclkvfpoint == NULL) {
return -ENOMEM;
}
status = pmu_boardobj_construct_super(g,
(struct boardobj *)(void *)pclkvfpoint, pargs);
if (status != 0) {
return -EINVAL;
}
pclkvfpoint = (struct clk_vf_point *)*ppboardobj;
*ppboardobj = (struct boardobj *)(void *)pclkvfpoint;
pclkvfpoint->super.pmudatainit =
_clk_vf_point_pmudatainit_super;

View File

@@ -370,19 +370,25 @@ static int vin_device_construct_v20(struct gk20a *g,
return status;
}
static int vin_device_construct_super(struct gk20a *g,
struct boardobj **ppboardobj, size_t size, void *pargs)
struct boardobj **obj, size_t size, void *pargs)
{
struct clk_vin_device *pvin_device;
struct clk_vin_device *ptmpvin_device =
(struct clk_vin_device *)pargs;
int status = 0;
status = nvgpu_boardobj_construct_super(g, ppboardobj, size, pargs);
pvin_device = nvgpu_kzalloc(g, size);
if (pvin_device == NULL) {
return -ENOMEM;
}
status = pmu_boardobj_construct_super(g,
(struct boardobj *)(void *)pvin_device, pargs);
if (status != 0) {
return -EINVAL;
}
pvin_device = (struct clk_vin_device *)*ppboardobj;
*obj = (struct boardobj *)(void *)pvin_device;
pvin_device->super.pmudatainit =
vin_device_init_pmudata_super;

View File

@@ -115,20 +115,26 @@ static int pstate_init_pmudata(struct gk20a *g,
return status;
}
static int pstate_construct_super(struct gk20a *g, struct boardobj **ppboardobj,
size_t size, void *args)
static int pstate_construct_super(struct gk20a *g, struct boardobj *ppboardobj,
void *args)
{
return nvgpu_boardobj_construct_super(g, ppboardobj, size, args);
int status;
status = pmu_boardobj_construct_super(g, ppboardobj, args);
if (status != 0) {
return -EINVAL;
}
return 0;
}
static int pstate_construct_35(struct gk20a *g, struct boardobj **ppboardobj,
u16 size, void *args)
static int pstate_construct_35(struct gk20a *g, struct boardobj *ppboardobj,
void *args)
{
struct boardobj *ptmpobj = (struct boardobj *)args;
ptmpobj->type_mask |= BIT32(CTRL_PERF_PSTATE_TYPE_35);
return pstate_construct_super(g, ppboardobj, size, args);
return pstate_construct_super(g, ppboardobj, args);
}
static struct pstate *pstate_construct(struct gk20a *g, void *args)
@@ -138,8 +144,12 @@ static struct pstate *pstate_construct(struct gk20a *g, void *args)
int status;
u32 clkidx;
status = pstate_construct_35(g, (struct boardobj **)&pstate,
(u16)sizeof(struct pstate), args);
pstate = nvgpu_kzalloc(g, sizeof(struct pstate));
if (pstate == NULL) {
return NULL;
}
status = pstate_construct_35(g, (struct boardobj *)(void *)pstate, args);
if (status != 0) {
nvgpu_err(g,
"error constructing pstate num=%u", ptmppstate->num);

View File

@@ -290,13 +290,19 @@ static int vfe_equ_construct_super(struct gk20a *g,
struct vfe_equ *ptmpequ = (struct vfe_equ *)pargs;
int status = 0;
status = nvgpu_boardobj_construct_super(g, ppboardobj,
size, pargs);
pvfeequ = nvgpu_kzalloc(g, size);
if (pvfeequ == NULL) {
return -ENOMEM;
}
status = pmu_boardobj_construct_super(g,
(struct boardobj *)(void *)pvfeequ, pargs);
if (status != 0) {
return -EINVAL;
}
pvfeequ = (struct vfe_equ *)(void *)*ppboardobj;
*ppboardobj = (struct boardobj *)(void *)pvfeequ;
status = boardobjgrpmask_e32_init(&pvfeequ->mask_depending_vars, NULL);
pvfeequ->super.pmudatainit =
vfe_equ_pmudatainit_super;

View File

@@ -344,12 +344,18 @@ static int vfe_var_construct_super(struct gk20a *g,
struct vfe_var *ptmpvar = (struct vfe_var *)pargs;
int status;
status = nvgpu_boardobj_construct_super(g, ppboardobj, size, pargs);
pvfevar = nvgpu_kzalloc(g, size);
if (pvfevar == NULL) {
return -ENOMEM;
}
status = pmu_boardobj_construct_super(g,
(struct boardobj *)(void *)pvfevar, pargs);
if (status != 0) {
return -EINVAL;
}
pvfevar = (struct vfe_var *)(void *)*ppboardobj;
*ppboardobj = (struct boardobj *)(void *)pvfevar;
pvfevar->super.pmudatainit =
vfe_var_pmudatainit_super;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2019, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2016-2020, NVIDIA CORPORATION. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -99,13 +99,18 @@ static struct boardobj *construct_pwr_device(struct gk20a *g,
struct pwr_device_ina3221 *pwrdev;
struct pwr_device_ina3221 *ina3221 = (struct pwr_device_ina3221*)pargs;
status = nvgpu_boardobj_construct_super(g, &board_obj_ptr,
pargs_size, pargs);
pwrdev = nvgpu_kzalloc(g, pargs_size);
if (pwrdev == NULL) {
return NULL;
}
board_obj_ptr = (struct boardobj *)(void *)pwrdev;
status = pmu_boardobj_construct_super(g, board_obj_ptr, pargs);
if (status != 0) {
return NULL;
}
pwrdev = (struct pwr_device_ina3221*)board_obj_ptr;
pwrdev = (struct pwr_device_ina3221*)(void *)board_obj_ptr;
/* Set Super class interfaces */
board_obj_ptr->pmudatainit = _pwr_domains_pmudatainit_ina3221;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2019, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2016-2020, NVIDIA CORPORATION. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -151,8 +151,13 @@ static struct boardobj *construct_pwr_topology(struct gk20a *g,
struct pwr_channel_sensor *pwrchannel;
struct pwr_channel_sensor *sensor = (struct pwr_channel_sensor*)pargs;
status = nvgpu_boardobj_construct_super(g, &board_obj_ptr,
pargs_size, pargs);
pwrchannel = nvgpu_kzalloc(g, pargs_size);
if (pwrchannel == NULL) {
return NULL;
}
board_obj_ptr = (struct boardobj *)(void *)pwrchannel;
status = pmu_boardobj_construct_super(g, board_obj_ptr, pargs);
if (status != 0) {
return NULL;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2019, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2016-2020, NVIDIA CORPORATION. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -264,8 +264,13 @@ static struct boardobj *construct_pwr_policy(struct gk20a *g,
struct pwr_policy *pwrpolicyparams = (struct pwr_policy*)pargs;
struct pwr_policy_hw_threshold *hwthreshold = (struct pwr_policy_hw_threshold*)pargs;
status = nvgpu_boardobj_construct_super(g, &board_obj_ptr,
pargs_size, pargs);
pwrpolicy = nvgpu_kzalloc(g, pargs_size);
if (pwrpolicy == NULL) {
return NULL;
}
board_obj_ptr = (struct boardobj *)(void *)pwrpolicy;
status = pmu_boardobj_construct_super(g, board_obj_ptr, pargs);
if (status != 0) {
return NULL;
}

View File

@@ -77,8 +77,13 @@ static struct boardobj *construct_channel_device(struct gk20a *g,
u16 scale_shift = BIT16(8);
struct therm_channel_device *therm_device = (struct therm_channel_device*)pargs;
status = nvgpu_boardobj_construct_super(g, &board_obj_ptr,
pargs_size, pargs);
pchannel_device = nvgpu_kzalloc(g, pargs_size);
if (pchannel_device == NULL) {
return NULL;
}
board_obj_ptr = (struct boardobj *)(void *)pchannel_device;
status = pmu_boardobj_construct_super(g, board_obj_ptr, pargs);
if (status != 0) {
return NULL;
}

View File

@@ -64,27 +64,33 @@ static int _therm_device_pmudata_instget(struct gk20a *g,
}
static int construct_therm_device(struct gk20a *g,
struct boardobj **ppboardobj, size_t size, void *pargs)
struct boardobj *ppboardobj, void *pargs)
{
return nvgpu_boardobj_construct_super(g, ppboardobj, size, pargs);
return pmu_boardobj_construct_super(g, ppboardobj, pargs);
}
static int construct_therm_device_gpu(struct gk20a *g,
struct boardobj **ppboardobj, size_t size, void *pargs)
struct boardobj *ppboardobj, void *pargs)
{
return construct_therm_device(g, ppboardobj, size, pargs);
return construct_therm_device(g, ppboardobj, pargs);
}
static struct boardobj *therm_device_construct(struct gk20a *g,
void *pargs)
{
struct boardobj *board_obj_ptr = NULL;
struct therm_device *ptherm_device = NULL;
int status = 0;
ptherm_device = nvgpu_kzalloc(g, sizeof(struct therm_device));
if (ptherm_device == NULL) {
return NULL;
}
board_obj_ptr = (struct boardobj *)(void *)ptherm_device;
if (BOARDOBJ_GET_TYPE(pargs) ==
NV_VBIOS_THERM_DEVICE_1X_ENTRY_CLASS_GPU) {
status = construct_therm_device_gpu(g, &board_obj_ptr,
sizeof(struct therm_device), pargs);
status = construct_therm_device_gpu(g, board_obj_ptr, pargs);
} else {
nvgpu_err(g, "unsupported therm_device class - 0x%x",
BOARDOBJ_GET_TYPE(pargs));

View File

@@ -91,12 +91,18 @@ static int volt_construct_volt_device(struct gk20a *g,
struct voltage_device *pvolt_dev = NULL;
int status = 0;
status = nvgpu_boardobj_construct_super(g, ppboardobj, size, pargs);
if (status != 0) {
return status;
pvolt_dev = nvgpu_kzalloc(g, size);
if (pvolt_dev == NULL) {
return -ENOMEM;
}
pvolt_dev = (struct voltage_device *)*ppboardobj;
status = pmu_boardobj_construct_super(g,
(struct boardobj *)(void *)pvolt_dev, pargs);
if (status != 0) {
return -EINVAL;
}
*ppboardobj = (struct boardobj *)(void *)pvolt_dev;
pvolt_dev->volt_domain = ptmp_dev->volt_domain;
pvolt_dev->i2c_dev_idx = ptmp_dev->i2c_dev_idx;

View File

@@ -45,12 +45,18 @@ static int volt_construct_volt_policy(struct gk20a *g,
struct voltage_policy *pvolt_policy = NULL;
int status = 0;
status = nvgpu_boardobj_construct_super(g, ppboardobj, size, pArgs);
if (status != 0) {
return status;
pvolt_policy = nvgpu_kzalloc(g, size);
if (pvolt_policy == NULL) {
return -ENOMEM;
}
pvolt_policy = (struct voltage_policy *)*ppboardobj;
status = pmu_boardobj_construct_super(g,
(struct boardobj *)(void *)pvolt_policy, pArgs);
if (status != 0) {
return -EINVAL;
}
*ppboardobj = (struct boardobj *)(void *)pvolt_policy;
pvolt_policy->super.pmudatainit = volt_policy_pmu_data_init_super;

View File

@@ -127,13 +127,19 @@ static struct voltage_rail *volt_construct_volt_rail(struct gk20a *g, void *parg
int status;
nvgpu_log_info(g, " ");
status = nvgpu_boardobj_construct_super(g, &board_obj_ptr,
sizeof(struct voltage_rail), pargs);
board_obj_volt_rail_ptr = nvgpu_kzalloc(g, sizeof(struct voltage_rail));
if (board_obj_volt_rail_ptr == NULL) {
return NULL;
}
status = pmu_boardobj_construct_super(g,
(struct boardobj *)(void *)board_obj_volt_rail_ptr, pargs);
if (status != 0) {
return NULL;
}
board_obj_volt_rail_ptr = (struct voltage_rail *)board_obj_ptr;
board_obj_ptr = (struct boardobj *)(void *)board_obj_volt_rail_ptr;
/* override super class interface */
board_obj_ptr->pmudatainit = volt_rail_init_pmudata_super;