video: tegra: host: gk20a: Check for free va fail
Terje Bergstrom [Tue, 4 Mar 2014 13:05:06 +0000 (15:05 +0200)]
Return error if freeing virtual address space fails. Do not try to
free graphics context that has not been allocated.

Change-Id: I1c22650aae25038d56582e00b8906532ace482f1
Signed-off-by: Terje Bergstrom <tbergstrom@nvidia.com>
Reviewed-on: http://git-master/r/382474
(cherry picked from commit 20a8917aaa7c6bbad3c74f5279fb8b142f858e77)
Reviewed-on: http://git-master/r/391823
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Matthew Pedro <mapedro@nvidia.com>
Tested-by: Matthew Pedro <mapedro@nvidia.com>

drivers/video/tegra/host/gk20a/gr_gk20a.c
drivers/video/tegra/host/gk20a/mm_gk20a.c

index 67ce9b2..4caaa51 100644 (file)
@@ -2523,6 +2523,9 @@ static void gr_gk20a_free_channel_gr_ctx(struct channel_gk20a *c)
 
        nvhost_dbg_fn("");
 
+       if (!ch_ctx->gr_ctx.gpu_va)
+               return;
+
        gk20a_gmmu_unmap(ch_vm, ch_ctx->gr_ctx.gpu_va,
                        ch_ctx->gr_ctx.size, mem_flag_none);
        dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING, &attrs);
index 2542dc4..fdb750e 100644 (file)
@@ -687,7 +687,7 @@ static u64 gk20a_vm_alloc_va(struct vm_gk20a *vm,
        return offset;
 }
 
-static void gk20a_vm_free_va(struct vm_gk20a *vm,
+static int gk20a_vm_free_va(struct vm_gk20a *vm,
                             u64 offset, u64 size,
                             enum gmmu_pgsz_gk20a pgsz_idx)
 {
@@ -709,6 +709,8 @@ static void gk20a_vm_free_va(struct vm_gk20a *vm,
                           "not found: offset=0x%llx, sz=0x%llx",
                           offset, size);
        }
+
+       return err;
 }
 
 static int insert_mapped_buffer(struct rb_root *root,
@@ -1019,8 +1021,14 @@ static void __locked_gmmu_unmap(struct vm_gk20a *vm,
        int err = 0;
        struct gk20a *g = gk20a_from_vm(vm);
 
-       if (va_allocated)
-               gk20a_vm_free_va(vm, vaddr, size, pgsz_idx);
+       if (va_allocated) {
+               err = gk20a_vm_free_va(vm, vaddr, size, pgsz_idx);
+               if (err) {
+                       dev_err(dev_from_vm(vm),
+                               "failed to free va");
+                       return;
+               }
+       }
 
        /* unmap here needs to know the page size we assigned at mapping */
        err = update_gmmu_ptes_locked(vm,