gpu: nvgpu: add checks for kzalloc() allocations

Check kzalloc() allocations for failures and return
an error if an allocation fails.

Bug 2279948

Change-Id: I8a2c3b84904da897ad6118900c11489c8656c20f
Signed-off-by: Nitin Kumbhar <nkumbhar@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/2020123
GVS: Gerrit_Virtual_Submit
Reviewed-by: Debarshi Dutta <ddutta@nvidia.com>
Reviewed-by: Deepak Nibade <dnibade@nvidia.com>
Reviewed-by: Bharat Nihalani <bnihalani@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:
Nitin Kumbhar
2019-02-15 15:16:17 +05:30
committed by mobile promotions
parent 173800a7cd
commit fadd0014da
5 changed files with 29 additions and 0 deletions

View File

@@ -614,6 +614,8 @@ static u32 clk_prog_construct_1x_master(struct gk20a *g,
pclkprog->p_vf_entries = (struct ctrl_clk_clk_prog_1x_master_vf_entry *) pclkprog->p_vf_entries = (struct ctrl_clk_clk_prog_1x_master_vf_entry *)
kzalloc(vfsize, GFP_KERNEL); kzalloc(vfsize, GFP_KERNEL);
if (!pclkprog->p_vf_entries)
return -ENOMEM;
memcpy(pclkprog->p_vf_entries, ptmpprog->p_vf_entries, vfsize); memcpy(pclkprog->p_vf_entries, ptmpprog->p_vf_entries, vfsize);

View File

@@ -459,6 +459,8 @@ static int nvgpu_gpu_ioctl_wait_for_pause(struct gk20a *g,
sm_count = g->gr.gpc_count * g->gr.tpc_count; sm_count = g->gr.gpc_count * g->gr.tpc_count;
size = sm_count * sizeof(struct warpstate); size = sm_count * sizeof(struct warpstate);
w_state = kzalloc(size, GFP_KERNEL); w_state = kzalloc(size, GFP_KERNEL);
if (w_state == NULL)
return -ENOMEM;
/* Wait for the SMs to reach full stop. This condition is: /* Wait for the SMs to reach full stop. This condition is:
* 1) All SMs with valid warps must be in the trap handler (SM_IN_TRAP_MODE) * 1) All SMs with valid warps must be in the trap handler (SM_IN_TRAP_MODE)

View File

@@ -334,6 +334,8 @@ void gk20a_scale_init(struct device *dev)
return; return;
profile = kzalloc(sizeof(*profile), GFP_KERNEL); profile = kzalloc(sizeof(*profile), GFP_KERNEL);
if (!profile)
return;
profile->dev = dev; profile->dev = dev;
profile->dev_stat.busy = false; profile->dev_stat.busy = false;

View File

@@ -3593,6 +3593,9 @@ static int gr_gk20a_init_gr_config(struct gk20a *g, struct gr_gk20a *gr)
gr->sm_to_cluster = kzalloc(gr->gpc_count * gr->tpc_count * gr->sm_to_cluster = kzalloc(gr->gpc_count * gr->tpc_count *
sizeof(struct sm_info), GFP_KERNEL); sizeof(struct sm_info), GFP_KERNEL);
if (!gr->sm_to_cluster)
goto clean_up;
gr->no_of_sm = 0; gr->no_of_sm = 0;
gk20a_dbg_info("fbps: %d", gr->num_fbps); gk20a_dbg_info("fbps: %d", gr->num_fbps);

View File

@@ -571,8 +571,19 @@ static int ecc_stat_create(struct device *dev,
dev_attr_array = kzalloc(sizeof(struct device_attribute) * num_hw_units, GFP_KERNEL); dev_attr_array = kzalloc(sizeof(struct device_attribute) * num_hw_units, GFP_KERNEL);
ecc_stat->counters = kzalloc(sizeof(u32) * num_hw_units, GFP_KERNEL); ecc_stat->counters = kzalloc(sizeof(u32) * num_hw_units, GFP_KERNEL);
ecc_stat->names = kzalloc(sizeof(char *) * num_hw_units, GFP_KERNEL); ecc_stat->names = kzalloc(sizeof(char *) * num_hw_units, GFP_KERNEL);
if (!dev_attr_array || !ecc_stat->counters || !ecc_stat->names) {
error = -ENOMEM;
goto clean_up;
}
for (hw_unit = 0; hw_unit < num_hw_units; hw_unit++) { for (hw_unit = 0; hw_unit < num_hw_units; hw_unit++) {
ecc_stat->names[hw_unit] = kzalloc(sizeof(char) * ECC_STAT_NAME_MAX_SIZE, GFP_KERNEL); ecc_stat->names[hw_unit] = kzalloc(sizeof(char) * ECC_STAT_NAME_MAX_SIZE, GFP_KERNEL);
if (!ecc_stat->names[hw_unit]) {
hw_unit--;
error = -ENOMEM;
goto clean_up;
}
} }
for (hw_unit = 0; hw_unit < num_hw_units; hw_unit++) { for (hw_unit = 0; hw_unit < num_hw_units; hw_unit++) {
@@ -605,6 +616,15 @@ static int ecc_stat_create(struct device *dev,
hash_add(ecc_hash_table, hash_add(ecc_hash_table,
&ecc_stat->hash_node, &ecc_stat->hash_node,
hash_key); hash_key);
return 0;
clean_up:
for (;hw_unit >= 0; hw_unit--) {
kfree(ecc_stat->names[hw_unit]);
}
kfree(ecc_stat->names);
kfree(ecc_stat->counters);
kfree(dev_attr_array);
return error; return error;
} }