From fe868356339182f0aa21a4424f5ef08229f8ebd6 Mon Sep 17 00:00:00 2001 From: Deepak Nibade Date: Mon, 5 Jun 2017 14:35:07 +0530 Subject: gpu: nvgpu: fix resource leak We pass (struct device_attribute *) to gp10b_ecc_stat_create() and gr_gp10b_ecc_stat_create() and then assign a memory allocation to this pointer But since this pointer is local copy to function, static pointer variables are never set in gr_gp10b_create_sysfs() This also results in a resource leak since we never free the storage assigned to local variable Fix this by adding correct parameter (struct device_attribute **) so that the address of the allocation is returned to the caller correctly Bug 200291879 Coverity id : 2567934 Change-Id: I7ac79810d9e22a568ae3cd1a69eb3f59a8d356ac Signed-off-by: Deepak Nibade Reviewed-on: http://git-master/r/1495905 Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Sachin Nikam Reviewed-by: svccoveritychecker --- .../gpu/nvgpu/tegra/linux/platform_gp10b_tegra.c | 37 ++++++++++++---------- .../gpu/nvgpu/tegra/linux/platform_gp10b_tegra.h | 4 +-- 2 files changed, 22 insertions(+), 19 deletions(-) (limited to 'drivers/gpu/nvgpu') diff --git a/drivers/gpu/nvgpu/tegra/linux/platform_gp10b_tegra.c b/drivers/gpu/nvgpu/tegra/linux/platform_gp10b_tegra.c index a2878c8b..b7cbf56e 100644 --- a/drivers/gpu/nvgpu/tegra/linux/platform_gp10b_tegra.c +++ b/drivers/gpu/nvgpu/tegra/linux/platform_gp10b_tegra.c @@ -518,7 +518,7 @@ int gr_gp10b_ecc_stat_create(struct device *dev, int is_l2, char *ecc_stat_name, struct gk20a_ecc_stat *ecc_stat, - struct device_attribute *dev_attr_array) + struct device_attribute **dev_attr_array) { struct gk20a *g = get_gk20a(dev); char *ltc_unit_name = "ltc"; @@ -543,12 +543,13 @@ int gp10b_ecc_stat_create(struct device *dev, char *ecc_unit_name, char *ecc_stat_name, struct gk20a_ecc_stat *ecc_stat, - struct device_attribute *dev_attr_array) + struct device_attribute **__dev_attr_array) { int error = 0; struct gk20a *g = get_gk20a(dev); int hw_unit = 0; u32 hash_key = 0; + struct device_attribute *dev_attr_array; /* Allocate arrays */ dev_attr_array = nvgpu_kzalloc(g, sizeof(struct device_attribute) * @@ -585,6 +586,8 @@ int gp10b_ecc_stat_create(struct device *dev, &ecc_stat->hash_node, hash_key); + *__dev_attr_array = dev_attr_array; + return error; } @@ -645,80 +648,80 @@ void gr_gp10b_create_sysfs(struct device *dev) 0, "sm_lrf_ecc_single_err_count", &g->ecc.gr.t18x.sm_lrf_single_err_count, - dev_attr_sm_lrf_ecc_single_err_count_array); + &dev_attr_sm_lrf_ecc_single_err_count_array); error |= gr_gp10b_ecc_stat_create(dev, 0, "sm_lrf_ecc_double_err_count", &g->ecc.gr.t18x.sm_lrf_double_err_count, - dev_attr_sm_lrf_ecc_double_err_count_array); + &dev_attr_sm_lrf_ecc_double_err_count_array); error |= gr_gp10b_ecc_stat_create(dev, 0, "sm_shm_ecc_sec_count", &g->ecc.gr.t18x.sm_shm_sec_count, - dev_attr_sm_shm_ecc_sec_count_array); + &dev_attr_sm_shm_ecc_sec_count_array); error |= gr_gp10b_ecc_stat_create(dev, 0, "sm_shm_ecc_sed_count", &g->ecc.gr.t18x.sm_shm_sed_count, - dev_attr_sm_shm_ecc_sed_count_array); + &dev_attr_sm_shm_ecc_sed_count_array); error |= gr_gp10b_ecc_stat_create(dev, 0, "sm_shm_ecc_ded_count", &g->ecc.gr.t18x.sm_shm_ded_count, - dev_attr_sm_shm_ecc_ded_count_array); + &dev_attr_sm_shm_ecc_ded_count_array); error |= gr_gp10b_ecc_stat_create(dev, 0, "tex_ecc_total_sec_pipe0_count", &g->ecc.gr.t18x.tex_total_sec_pipe0_count, - dev_attr_tex_ecc_total_sec_pipe0_count_array); + &dev_attr_tex_ecc_total_sec_pipe0_count_array); error |= gr_gp10b_ecc_stat_create(dev, 0, "tex_ecc_total_ded_pipe0_count", &g->ecc.gr.t18x.tex_total_ded_pipe0_count, - dev_attr_tex_ecc_total_ded_pipe0_count_array); + &dev_attr_tex_ecc_total_ded_pipe0_count_array); error |= gr_gp10b_ecc_stat_create(dev, 0, "tex_ecc_unique_sec_pipe0_count", &g->ecc.gr.t18x.tex_unique_sec_pipe0_count, - dev_attr_tex_ecc_unique_sec_pipe0_count_array); + &dev_attr_tex_ecc_unique_sec_pipe0_count_array); error |= gr_gp10b_ecc_stat_create(dev, 0, "tex_ecc_unique_ded_pipe0_count", &g->ecc.gr.t18x.tex_unique_ded_pipe0_count, - dev_attr_tex_ecc_unique_ded_pipe0_count_array); + &dev_attr_tex_ecc_unique_ded_pipe0_count_array); error |= gr_gp10b_ecc_stat_create(dev, 0, "tex_ecc_total_sec_pipe1_count", &g->ecc.gr.t18x.tex_total_sec_pipe1_count, - dev_attr_tex_ecc_total_sec_pipe1_count_array); + &dev_attr_tex_ecc_total_sec_pipe1_count_array); error |= gr_gp10b_ecc_stat_create(dev, 0, "tex_ecc_total_ded_pipe1_count", &g->ecc.gr.t18x.tex_total_ded_pipe1_count, - dev_attr_tex_ecc_total_ded_pipe1_count_array); + &dev_attr_tex_ecc_total_ded_pipe1_count_array); error |= gr_gp10b_ecc_stat_create(dev, 0, "tex_ecc_unique_sec_pipe1_count", &g->ecc.gr.t18x.tex_unique_sec_pipe1_count, - dev_attr_tex_ecc_unique_sec_pipe1_count_array); + &dev_attr_tex_ecc_unique_sec_pipe1_count_array); error |= gr_gp10b_ecc_stat_create(dev, 0, "tex_ecc_unique_ded_pipe1_count", &g->ecc.gr.t18x.tex_unique_ded_pipe1_count, - dev_attr_tex_ecc_unique_ded_pipe1_count_array); + &dev_attr_tex_ecc_unique_ded_pipe1_count_array); error |= gr_gp10b_ecc_stat_create(dev, 1, "lts0_ecc_sec_count", &g->ecc.gr.t18x.l2_sec_count, - dev_attr_l2_ecc_sec_count_array); + &dev_attr_l2_ecc_sec_count_array); error |= gr_gp10b_ecc_stat_create(dev, 1, "lts0_ecc_ded_count", &g->ecc.gr.t18x.l2_ded_count, - dev_attr_l2_ecc_ded_count_array); + &dev_attr_l2_ecc_ded_count_array); if (error) dev_err(dev, "Failed to create sysfs attributes!\n"); diff --git a/drivers/gpu/nvgpu/tegra/linux/platform_gp10b_tegra.h b/drivers/gpu/nvgpu/tegra/linux/platform_gp10b_tegra.h index fb69fa98..74db60d1 100644 --- a/drivers/gpu/nvgpu/tegra/linux/platform_gp10b_tegra.h +++ b/drivers/gpu/nvgpu/tegra/linux/platform_gp10b_tegra.h @@ -23,13 +23,13 @@ int gr_gp10b_ecc_stat_create(struct device *dev, int is_l2, char *ecc_stat_name, struct gk20a_ecc_stat *ecc_stat, - struct device_attribute *dev_attr_array); + struct device_attribute **dev_attr_array); int gp10b_ecc_stat_create(struct device *dev, int hw_units, char *ecc_unit_name, char *ecc_stat_name, struct gk20a_ecc_stat *ecc_stat, - struct device_attribute *dev_attr_array); + struct device_attribute **dev_attr_array); void gr_gp10b_ecc_stat_remove(struct device *dev, int is_l2, -- cgit v1.2.2