From 2d7eb09ab4a2bbb6ce8ec220844fae079e7345fe Mon Sep 17 00:00:00 2001 From: Thomas Fleury Date: Thu, 6 Feb 2020 18:28:13 -0500 Subject: [PATCH] gpu: nvgpu: free g->bios on sw init failure nvgpu_bios_sw_init was not freeing g->bios on init failure (for instance when board does not complete devinit). As a result, the function was skipping init at the next nvgpu_finalize_poweron attempt. This was resulting in a crash later on, when attempting to parse VBIOS data. Changed nvgpu_bios_sw_init to free g->bios and set it to NULL, in case init fails. Bug 2834853 Change-Id: I87bc18b89674141f713c4043a231a437669c9c94 Signed-off-by: Thomas Fleury Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2291246 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-misra Reviewed-by: svc-mobile-cert Reviewed-by: Vinod Gopalakrishnakurup Reviewed-by: mobile promotions GVS: Gerrit_Virtual_Submit Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/vbios/bios.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/nvgpu/common/vbios/bios.c b/drivers/gpu/nvgpu/common/vbios/bios.c index 379f08fa9..8a6febee4 100644 --- a/drivers/gpu/nvgpu/common/vbios/bios.c +++ b/drivers/gpu/nvgpu/common/vbios/bios.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2015-2020, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -188,20 +188,24 @@ int nvgpu_bios_sw_init(struct gk20a *g) nvgpu_tu104_bios_sw_init(g, g->bios); break; default: - nvgpu_kfree(g, g->bios); - err = 0; - break; + goto clean_bios; } if ((g->bios)->init != NULL) { err = g->bios->init(g); if (err != 0) { nvgpu_falcon_sw_free(g, FALCON_ID_FECS); + goto clean_bios; } - goto done; } done: return err; + +clean_bios: + nvgpu_kfree(g, g->bios); + g->bios = NULL; + return err; + } void nvgpu_bios_sw_deinit(struct gk20a *g, struct nvgpu_bios *bios)