mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-22 17:36:20 +03:00
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>
This commit is contained in:
committed by
mobile promotions
parent
838ba0a14d
commit
c03ccd89c2
@@ -167,6 +167,7 @@ fail_free:
|
|||||||
dma_free_coherent(d, size, mem->cpu_va, iova);
|
dma_free_coherent(d, size, mem->cpu_va, iova);
|
||||||
mem->cpu_va = NULL;
|
mem->cpu_va = NULL;
|
||||||
mem->priv.sgt = NULL;
|
mem->priv.sgt = NULL;
|
||||||
|
mem->size = 0;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,6 +254,7 @@ fail_kfree:
|
|||||||
nvgpu_kfree(g, mem->priv.sgt);
|
nvgpu_kfree(g, mem->priv.sgt);
|
||||||
fail_physfree:
|
fail_physfree:
|
||||||
nvgpu_free(&g->mm.vidmem.allocator, addr);
|
nvgpu_free(&g->mm.vidmem.allocator, addr);
|
||||||
|
mem->size = 0;
|
||||||
return err;
|
return err;
|
||||||
#else
|
#else
|
||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ struct nvgpu_gmmu_attrs;
|
|||||||
* memory actually was allocated from.
|
* memory actually was allocated from.
|
||||||
*/
|
*/
|
||||||
enum nvgpu_aperture {
|
enum nvgpu_aperture {
|
||||||
APERTURE_INVALID, /* unallocated or N/A */
|
APERTURE_INVALID = 0, /* unallocated or N/A */
|
||||||
APERTURE_SYSMEM,
|
APERTURE_SYSMEM,
|
||||||
APERTURE_VIDMEM
|
APERTURE_VIDMEM
|
||||||
};
|
};
|
||||||
@@ -122,6 +122,24 @@ static inline const char *nvgpu_aperture_str(enum nvgpu_aperture aperture)
|
|||||||
return "UNKNOWN";
|
return "UNKNOWN";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns true if the passed nvgpu_mem has been allocated (i.e it's valid for
|
||||||
|
* subsequent use).
|
||||||
|
*/
|
||||||
|
static inline bool nvgpu_mem_is_valid(struct nvgpu_mem *mem)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Internally the DMA APIs must set/unset the aperture flag when
|
||||||
|
* allocating/freeing the buffer. So check that to see if the *mem
|
||||||
|
* has been allocated or not.
|
||||||
|
*
|
||||||
|
* This relies on mem_descs being zeroed before being initialized since
|
||||||
|
* APERTURE_INVALID is equal to 0.
|
||||||
|
*/
|
||||||
|
return mem->aperture != APERTURE_INVALID;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nvgpu_mem_create_from_mem - Create a new nvgpu_mem struct from an old one.
|
* nvgpu_mem_create_from_mem - Create a new nvgpu_mem struct from an old one.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user