From f37f4e27e362629d5c187817104d48d703c380cc Mon Sep 17 00:00:00 2001 From: Terje Bergstrom Date: Tue, 20 Dec 2016 14:11:54 -0800 Subject: gpu: nvgpu: Use perf table only VBIOS supports it We retrieve perf table from VBIOS only if respective HAL op is implemented. Later in code we unconditionally dereference the pointer which can lead to NULL pointer access. Fix by early aborting creation of devinit tables if the perf VBIOS getter is missing. Change-Id: If48aa6dac724056dd1feb2ef520e343736d4db85 Signed-off-by: Terje Bergstrom Reviewed-on: http://git-master/r/1279223 GVS: Gerrit_Virtual_Submit Reviewed-by: Thomas Fleury --- drivers/gpu/nvgpu/perf/vfe_equ.c | 18 ++++++++++-------- drivers/gpu/nvgpu/perf/vfe_var.c | 27 ++++++++++++++------------- 2 files changed, 24 insertions(+), 21 deletions(-) (limited to 'drivers/gpu/nvgpu/perf') diff --git a/drivers/gpu/nvgpu/perf/vfe_equ.c b/drivers/gpu/nvgpu/perf/vfe_equ.c index 6630fb21..78a7c57c 100644 --- a/drivers/gpu/nvgpu/perf/vfe_equ.c +++ b/drivers/gpu/nvgpu/perf/vfe_equ.c @@ -150,14 +150,16 @@ static u32 devinit_get_vfe_equ_table(struct gk20a *g, gk20a_dbg_info(""); - if (g->ops.bios.get_perf_table_ptrs) { - vfeequs_tbl_ptr = (u8 *)g->ops.bios.get_perf_table_ptrs(g, - g->bios.perf_token, - CONTINUOUS_VIRTUAL_BINNING_TABLE); - if (vfeequs_tbl_ptr == NULL) { - status = -EINVAL; - goto done; - } + if (!g->ops.bios.get_perf_table_ptrs) + return -EINVAL; + + vfeequs_tbl_ptr = (u8 *)g->ops.bios.get_perf_table_ptrs(g, + g->bios.perf_token, + CONTINUOUS_VIRTUAL_BINNING_TABLE); + + if (vfeequs_tbl_ptr == NULL) { + status = -EINVAL; + goto done; } memcpy(&vfeequs_tbl_header, vfeequs_tbl_ptr, diff --git a/drivers/gpu/nvgpu/perf/vfe_var.c b/drivers/gpu/nvgpu/perf/vfe_var.c index 4f8dc83b..f4c3f276 100644 --- a/drivers/gpu/nvgpu/perf/vfe_var.c +++ b/drivers/gpu/nvgpu/perf/vfe_var.c @@ -182,20 +182,21 @@ u32 dev_init_get_vfield_info(struct gk20a *g, u8 *psegmentcount = NULL; u32 status = 0; - if (g->ops.bios.get_perf_table_ptrs) { - vfieldregtableptr = (u8 *)g->ops.bios.get_perf_table_ptrs(g, - g->bios.virt_token, VP_FIELD_REGISTER); - if (vfieldregtableptr == NULL) { - status = -EINVAL; - goto done; - } + if (!g->ops.bios.get_perf_table_ptrs) + return -EINVAL; - vfieldtableptr = (u8 *)g->ops.bios.get_perf_table_ptrs(g, - g->bios.virt_token, VP_FIELD_TABLE); - if (vfieldtableptr == NULL) { - status = -EINVAL; - goto done; - } + vfieldregtableptr = (u8 *)g->ops.bios.get_perf_table_ptrs(g, + g->bios.virt_token, VP_FIELD_REGISTER); + if (vfieldregtableptr == NULL) { + status = -EINVAL; + goto done; + } + + vfieldtableptr = (u8 *)g->ops.bios.get_perf_table_ptrs(g, + g->bios.virt_token, VP_FIELD_TABLE); + if (vfieldtableptr == NULL) { + status = -EINVAL; + goto done; } memcpy(&vregheader, vfieldregtableptr, VFIELD_REG_HEADER_SIZE); -- cgit v1.2.2