diff options
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/dma.c | 2 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h | 20 |
2 files changed, 21 insertions, 1 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/dma.c b/drivers/gpu/nvgpu/common/linux/dma.c index 13c1c347..43009fca 100644 --- a/drivers/gpu/nvgpu/common/linux/dma.c +++ b/drivers/gpu/nvgpu/common/linux/dma.c | |||
@@ -167,6 +167,7 @@ fail_free: | |||
167 | dma_free_coherent(d, size, mem->cpu_va, iova); | 167 | dma_free_coherent(d, size, mem->cpu_va, iova); |
168 | mem->cpu_va = NULL; | 168 | mem->cpu_va = NULL; |
169 | mem->priv.sgt = NULL; | 169 | mem->priv.sgt = NULL; |
170 | mem->size = 0; | ||
170 | return err; | 171 | return err; |
171 | } | 172 | } |
172 | 173 | ||
@@ -253,6 +254,7 @@ fail_kfree: | |||
253 | nvgpu_kfree(g, mem->priv.sgt); | 254 | nvgpu_kfree(g, mem->priv.sgt); |
254 | fail_physfree: | 255 | fail_physfree: |
255 | nvgpu_free(&g->mm.vidmem.allocator, addr); | 256 | nvgpu_free(&g->mm.vidmem.allocator, addr); |
257 | mem->size = 0; | ||
256 | return err; | 258 | return err; |
257 | #else | 259 | #else |
258 | return -ENOSYS; | 260 | return -ENOSYS; |
diff --git a/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h b/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h index f3be65c2..a112623e 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h +++ b/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h | |||
@@ -39,7 +39,7 @@ struct nvgpu_gmmu_attrs; | |||
39 | * memory actually was allocated from. | 39 | * memory actually was allocated from. |
40 | */ | 40 | */ |
41 | enum nvgpu_aperture { | 41 | enum nvgpu_aperture { |
42 | APERTURE_INVALID, /* unallocated or N/A */ | 42 | APERTURE_INVALID = 0, /* unallocated or N/A */ |
43 | APERTURE_SYSMEM, | 43 | APERTURE_SYSMEM, |
44 | APERTURE_VIDMEM | 44 | APERTURE_VIDMEM |
45 | }; | 45 | }; |
@@ -122,6 +122,24 @@ static inline const char *nvgpu_aperture_str(enum nvgpu_aperture aperture) | |||
122 | return "UNKNOWN"; | 122 | return "UNKNOWN"; |
123 | } | 123 | } |
124 | 124 | ||
125 | /* | ||
126 | * Returns true if the passed nvgpu_mem has been allocated (i.e it's valid for | ||
127 | * subsequent use). | ||
128 | */ | ||
129 | static inline bool nvgpu_mem_is_valid(struct nvgpu_mem *mem) | ||
130 | { | ||
131 | /* | ||
132 | * Internally the DMA APIs must set/unset the aperture flag when | ||
133 | * allocating/freeing the buffer. So check that to see if the *mem | ||
134 | * has been allocated or not. | ||
135 | * | ||
136 | * This relies on mem_descs being zeroed before being initialized since | ||
137 | * APERTURE_INVALID is equal to 0. | ||
138 | */ | ||
139 | return mem->aperture != APERTURE_INVALID; | ||
140 | |||
141 | } | ||
142 | |||
125 | /** | 143 | /** |
126 | * nvgpu_mem_create_from_mem - Create a new nvgpu_mem struct from an old one. | 144 | * nvgpu_mem_create_from_mem - Create a new nvgpu_mem struct from an old one. |
127 | * | 145 | * |