summaryrefslogtreecommitdiff
path: root/drivers/misc/habanalabs/common/mmu_v1.c
diff options
context:
space:
mode:
authorOded Gabbay <ogabbay@kernel.org>2021-01-11 16:00:38 +0300
committerOded Gabbay <ogabbay@kernel.org>2021-01-12 15:59:52 +0300
commitaa6df6533b8f9ead98889baa92e2b19793b1c77e (patch)
tree592984f950d9ffe10b1466a9ddc4d24a4ac24fd4 /drivers/misc/habanalabs/common/mmu_v1.c
parenta9d4ef643430d638de1910377f50e0d492d85a43 (diff)
downloadlinux-aa6df6533b8f9ead98889baa92e2b19793b1c77e.tar.xz
habanalabs: fix reset process in case of failures
There are some points in the reset process where if the code fails for some reason, and the system admin tries to initiate the reset process again we will get a kernel panic. This is because there aren't any protections in different fini functions that are called during the reset process. The protections that are added in this patch make sure that if the fini functions are called multiple times, without calling init functions between them, there won't be double release of already released resources. Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
Diffstat (limited to 'drivers/misc/habanalabs/common/mmu_v1.c')
-rw-r--r--drivers/misc/habanalabs/common/mmu_v1.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/drivers/misc/habanalabs/common/mmu_v1.c b/drivers/misc/habanalabs/common/mmu_v1.c
index 2ce6ea89d4fa..06d8a44dd5d4 100644
--- a/drivers/misc/habanalabs/common/mmu_v1.c
+++ b/drivers/misc/habanalabs/common/mmu_v1.c
@@ -467,8 +467,16 @@ static void hl_mmu_v1_fini(struct hl_device *hdev)
{
/* MMU H/W fini was already done in device hw_fini() */
- kvfree(hdev->mmu_priv.dr.mmu_shadow_hop0);
- gen_pool_destroy(hdev->mmu_priv.dr.mmu_pgt_pool);
+ if (!ZERO_OR_NULL_PTR(hdev->mmu_priv.hr.mmu_shadow_hop0)) {
+ kvfree(hdev->mmu_priv.dr.mmu_shadow_hop0);
+ gen_pool_destroy(hdev->mmu_priv.dr.mmu_pgt_pool);
+ }
+
+ /* Make sure that if we arrive here again without init was called we
+ * won't cause kernel panic. This can happen for example if we fail
+ * during hard reset code at certain points
+ */
+ hdev->mmu_priv.dr.mmu_shadow_hop0 = NULL;
}
/**