summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/include
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2017-09-13 17:03:34 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2017-09-19 02:15:51 -0400
commitc03ccd89c24572dcb65bdfc8d9ab5eb76da28c96 (patch)
tree8df70ca726b17749eeb034672231db46a1f7fb63 /drivers/gpu/nvgpu/include
parent838ba0a14d61ffde0d8631d1c6267694632234de (diff)
gpu: nvgpu: Add nvgpu_mem_is_valid() call
Add a function to check if an nvgpu_mem is allocated (valid) or not. Also fix possibly leaked state in nvgpu_mems when they fail to allocate. Also ensure that in the case of a failure to allocate no state is accidentally leaked to the caller. This should hopefully make it less likely that a caller thinks a buffer that failed to allocate is actually allocated. Change-Id: I43224ece7da84e63b2f43f36f04941126fabf3c7 Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1559419 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com> Reviewed-by: svccoveritychecker <svccoveritychecker@nvidia.com> GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/include')
-rw-r--r--drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h20
1 files changed, 19 insertions, 1 deletions
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 */
41enum nvgpu_aperture { 41enum 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 */
129static 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 *