summaryrefslogtreecommitdiff
path: root/tegra
diff options
context:
space:
mode:
authorThierry Reding <treding@nvidia.com>2018-04-23 10:58:09 +0200
committerThierry Reding <treding@nvidia.com>2022-02-23 15:38:21 +0100
commite44e7816037c54bae766df5b07af07685e81e336 (patch)
treead6bc21267557924b807be97e2ec5b33cccc2bab /tegra
parentbec2a28e98f430f4a82b085b4d1c69a98988359f (diff)
tegra: Extract common buffer object allocation code
All of the buffer object allocation functions use the same boilerplate code. Move that code into a separate function that can be reused. Reviewed-by: Mikko Perttunen <mperttunen@nvidia.com> Signed-off-by: Thierry Reding <treding@nvidia.com>
Diffstat (limited to 'tegra')
-rw-r--r--tegra/tegra.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/tegra/tegra.c b/tegra/tegra.c
index 630aea45..74e1fd33 100644
--- a/tegra/tegra.c
+++ b/tegra/tegra.c
@@ -97,6 +97,26 @@ drm_public void drm_tegra_close(struct drm_tegra *drm)
free(drm);
}
+static struct drm_tegra_bo *drm_tegra_bo_alloc(struct drm_tegra *drm,
+ uint32_t handle,
+ uint32_t flags,
+ uint32_t size)
+{
+ struct drm_tegra_bo *bo;
+
+ bo = calloc(1, sizeof(*bo));
+ if (!bo)
+ return NULL;
+
+ atomic_set(&bo->ref, 1);
+ bo->handle = handle;
+ bo->flags = flags;
+ bo->size = size;
+ bo->drm = drm;
+
+ return bo;
+}
+
drm_public int
drm_tegra_bo_new(struct drm_tegra_bo **bop, struct drm_tegra *drm,
uint32_t flags, uint32_t size)
@@ -108,15 +128,10 @@ drm_tegra_bo_new(struct drm_tegra_bo **bop, struct drm_tegra *drm,
if (!drm || size == 0 || !bop)
return -EINVAL;
- bo = calloc(1, sizeof(*bo));
+ bo = drm_tegra_bo_alloc(drm, 0, flags, size);
if (!bo)
return -ENOMEM;
- atomic_set(&bo->ref, 1);
- bo->flags = flags;
- bo->size = size;
- bo->drm = drm;
-
memset(&args, 0, sizeof(args));
args.flags = flags;
args.size = size;
@@ -145,16 +160,10 @@ drm_tegra_bo_wrap(struct drm_tegra_bo **bop, struct drm_tegra *drm,
if (!drm || !bop)
return -EINVAL;
- bo = calloc(1, sizeof(*bo));
+ bo = drm_tegra_bo_alloc(drm, handle, flags, size);
if (!bo)
return -ENOMEM;
- atomic_set(&bo->ref, 1);
- bo->handle = handle;
- bo->flags = flags;
- bo->size = size;
- bo->drm = drm;
-
*bop = bo;
return 0;