From a126e00e281ec865efbe76f543a2156c1de94679 Mon Sep 17 00:00:00 2001 From: vinodg Date: Wed, 8 Jan 2020 13:34:33 -0800 Subject: [PATCH] gpu: nvgpu: compile out unused code in gr init unit Add CONFIG_NVGPU_GRAPHICS check before calling g->gops>gr.init.preemption_state function. Add NULL checking of pointer before deferecing those pointers in de_init functions Jira NVGPU-4676 Change-Id: Id9be0aebdcab4a8fb2b03e92e67c1c207b5b8eab Signed-off-by: vinodg Reviewed-on: http://git-master.nvidia.com/r/c/linux-nvgpu/+/2276898 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/gr/global_ctx.c | 4 ++++ drivers/gpu/nvgpu/common/gr/gr.c | 2 ++ drivers/gpu/nvgpu/common/gr/gr_config.c | 4 ++++ drivers/gpu/nvgpu/common/gr/obj_ctx.c | 4 ++++ drivers/gpu/nvgpu/common/netlist/netlist.c | 4 ++++ 5 files changed, 18 insertions(+) diff --git a/drivers/gpu/nvgpu/common/gr/global_ctx.c b/drivers/gpu/nvgpu/common/gr/global_ctx.c index 4d5a79937..efd9cc7a7 100644 --- a/drivers/gpu/nvgpu/common/gr/global_ctx.c +++ b/drivers/gpu/nvgpu/common/gr/global_ctx.c @@ -94,6 +94,10 @@ void nvgpu_gr_global_ctx_buffer_free(struct gk20a *g, { u32 i; + if (desc == NULL) { + return; + } + for (i = 0; i < NVGPU_GR_GLOBAL_CTX_COUNT; i++) { if (desc[i].destroy != NULL) { desc[i].destroy(g, &desc[i].mem); diff --git a/drivers/gpu/nvgpu/common/gr/gr.c b/drivers/gpu/nvgpu/common/gr/gr.c index c24048a15..c7b84cb7c 100644 --- a/drivers/gpu/nvgpu/common/gr/gr.c +++ b/drivers/gpu/nvgpu/common/gr/gr.c @@ -267,12 +267,14 @@ static int gr_init_setup_hw(struct gk20a *g) g->ops.gr.init.su_coalesce(g, 0); g->ops.gr.init.lg_coalesce(g, 0); +#ifdef CONFIG_NVGPU_GRAPHICS if (g->ops.gr.init.preemption_state != NULL) { err = g->ops.gr.init.preemption_state(g); if (err != 0) { goto out; } } +#endif /* floorsweep anything left */ err = nvgpu_gr_fs_state_init(g, gr->config); diff --git a/drivers/gpu/nvgpu/common/gr/gr_config.c b/drivers/gpu/nvgpu/common/gr/gr_config.c index 1475db298..df934f4be 100644 --- a/drivers/gpu/nvgpu/common/gr/gr_config.c +++ b/drivers/gpu/nvgpu/common/gr/gr_config.c @@ -594,6 +594,10 @@ u32 nvgpu_gr_config_get_gpc_zcb_count(struct nvgpu_gr_config *config, void nvgpu_gr_config_deinit(struct gk20a *g, struct nvgpu_gr_config *config) { + if (config == NULL) { + return; + } + gr_config_free_mem(g, config); #ifdef CONFIG_NVGPU_GRAPHICS nvgpu_kfree(g, config->map_tiles); diff --git a/drivers/gpu/nvgpu/common/gr/obj_ctx.c b/drivers/gpu/nvgpu/common/gr/obj_ctx.c index 700a264e9..03dc860fb 100644 --- a/drivers/gpu/nvgpu/common/gr/obj_ctx.c +++ b/drivers/gpu/nvgpu/common/gr/obj_ctx.c @@ -899,6 +899,10 @@ int nvgpu_gr_obj_ctx_init(struct gk20a *g, void nvgpu_gr_obj_ctx_deinit(struct gk20a *g, struct nvgpu_gr_obj_ctx_golden_image *golden_image) { + if (golden_image == NULL) { + return; + } + if (golden_image->local_golden_image != NULL) { nvgpu_gr_global_ctx_deinit_local_golden_image(g, golden_image->local_golden_image); diff --git a/drivers/gpu/nvgpu/common/netlist/netlist.c b/drivers/gpu/nvgpu/common/netlist/netlist.c index 50f96f185..51dcfbf1b 100644 --- a/drivers/gpu/nvgpu/common/netlist/netlist.c +++ b/drivers/gpu/nvgpu/common/netlist/netlist.c @@ -610,6 +610,10 @@ void nvgpu_netlist_deinit_ctx_vars(struct gk20a *g) { struct nvgpu_netlist_vars *netlist_vars = g->netlist_vars; + if (netlist_vars == NULL) { + return; + } + g->netlist_valid = false; nvgpu_kfree(g, netlist_vars->ucode.fecs.inst.l); nvgpu_kfree(g, netlist_vars->ucode.fecs.data.l);