gpu: nvgpu: Add checking in allocator functions

Add checks to make sure function pointers are valid before attempting
to call said function.

Also, ensure that any allocator created defines the following 3 functions
at minimum:

  alloc()
  free()
  fini()

Bug 1799159

Change-Id: I4cd3d5746ccb721c723a161c9487564846027572
Signed-off-by: Alex Waterman <alexw@nvidia.com>
Reviewed-on: http://git-master/r/1200059
(cherry picked from commit e26557a49d7ca6629ada24f12a3be396b0ae22cd)
Reviewed-on: http://git-master/r/1208476
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
This commit is contained in:
Alex Waterman
2016-08-05 16:47:17 -07:00
committed by mobile promotions
parent 9eac0fd849
commit 9e43258438

View File

@@ -29,17 +29,23 @@ static struct dentry *gk20a_alloc_debugfs_root;
u64 gk20a_alloc_length(struct gk20a_allocator *a)
{
return a->ops->length(a);
if (a->ops->length)
return a->ops->length(a);
return 0;
}
u64 gk20a_alloc_base(struct gk20a_allocator *a)
{
return a->ops->base(a);
if (a->ops->base)
return a->ops->base(a);
return 0;
}
u64 gk20a_alloc_initialized(struct gk20a_allocator *a)
{
if (!a->ops)
if (!a->ops || !a->ops->inited)
return 0;
return a->ops->inited(a);
@@ -47,7 +53,10 @@ u64 gk20a_alloc_initialized(struct gk20a_allocator *a)
u64 gk20a_alloc_end(struct gk20a_allocator *a)
{
return a->ops->end(a);
if (a->ops->end)
return a->ops->end(a);
return 0;
}
u64 gk20a_alloc(struct gk20a_allocator *a, u64 len)
@@ -62,7 +71,10 @@ void gk20a_free(struct gk20a_allocator *a, u64 addr)
u64 gk20a_alloc_fixed(struct gk20a_allocator *a, u64 base, u64 len)
{
return a->ops->alloc_fixed(a, base, len);
if (a->ops->alloc_fixed)
return a->ops->alloc_fixed(a, base, len);
return 0;
}
void gk20a_free_fixed(struct gk20a_allocator *a, u64 base, u64 len)
@@ -92,6 +104,13 @@ int __gk20a_alloc_common_init(struct gk20a_allocator *a,
if (!ops)
return -EINVAL;
/*
* This is the bare minimum operations required for a sensible
* allocator.
*/
if (!ops->alloc || !ops->free || !ops->fini)
return -EINVAL;
a->ops = ops;
a->priv = priv;
a->debug = dbg;