gpu: nvgpu: add null check

As part of supporting GPU minimal boot, some of the HALs are assigned
with NULL. Before dereferencing such HALs, check for NULL.

Further, this patch reorganizes needs_init API to first check whether a
function pointer is NULL, to enable quick turnaround to the caller of this API.

JIRA NVGPU-9283

Change-Id: I768d1cddef8766948c99892c59f6ebe6f31be9d8
Signed-off-by: Rajesh Devaraj <rdevaraj@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2814225
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Rajesh Devaraj
2022-11-22 19:19:45 +00:00
committed by mobile promotions
parent 7abaeda619
commit 9143860355

View File

@@ -558,10 +558,12 @@ static int nvgpu_init_boot_clk_or_clk_arb(struct gk20a *g)
#endif #endif
{ {
#ifdef CONFIG_NVGPU_CLK_ARB #ifdef CONFIG_NVGPU_CLK_ARB
err = g->ops.clk_arb.clk_arb_init_arbiter(g); if (g->ops.clk_arb.clk_arb_init_arbiter != NULL) {
if (err != 0) { err = g->ops.clk_arb.clk_arb_init_arbiter(g);
nvgpu_err(g, "failed to init clk arb"); if (err != 0) {
return err; nvgpu_err(g, "failed to init clk arb");
return err;
}
} }
#endif #endif
} }
@@ -586,7 +588,9 @@ static int nvgpu_init_set_debugger_mode(struct gk20a *g)
(void)g; (void)g;
#ifdef CONFIG_NVGPU_DEBUGGER #ifdef CONFIG_NVGPU_DEBUGGER
/* Restore the debug setting */ /* Restore the debug setting */
g->ops.fb.set_debug_mode(g, g->mmu_debug_ctrl); if (g->ops.fb.set_debug_mode != NULL) {
g->ops.fb.set_debug_mode(g, g->mmu_debug_ctrl);
}
#endif #endif
return 0; return 0;
} }
@@ -709,8 +713,8 @@ struct nvgpu_init_table_t {
static bool needs_init(struct gk20a *g, nvgpu_init_func_t func, u32 enable_flag) static bool needs_init(struct gk20a *g, nvgpu_init_func_t func, u32 enable_flag)
{ {
return ((enable_flag == NO_FLAG) || return (func != NULL) && ((enable_flag == NO_FLAG) ||
nvgpu_is_enabled(g, enable_flag)) && (func != NULL); nvgpu_is_enabled(g, enable_flag));
} }
static int nvgpu_early_init(struct gk20a *g) static int nvgpu_early_init(struct gk20a *g)