From: Thierry Reding <thierry.reding@gmail.com>
To: Thierry Reding <thierry.reding@gmail.com>
Cc: linux-tegra@vger.kernel.org, "Dmitry Osipenko" <digetx@gmail.com>,
dri-devel@lists.freedesktop.org,
"Michał Mirosław" <mirq-linux@rere.qmqm.pl>
Subject: [PATCH libdrm v2 03/25] tegra: Extract common buffer object allocation code
Date: Thu, 17 Feb 2022 20:16:03 +0100 [thread overview]
Message-ID: <20220217191625.2534521-4-thierry.reding@gmail.com> (raw)
In-Reply-To: <20220217191625.2534521-1-thierry.reding@gmail.com>
From: Thierry Reding <treding@nvidia.com>
All of the buffer object allocation functions use the same boilerplate
code. Move that code into a separate function that can be reused.
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
tegra/tegra.c | 35 ++++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)
diff --git a/tegra/tegra.c b/tegra/tegra.c
index 630aea45f957..74e1fd33c6e5 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;
--
2.35.1
next prev parent reply other threads:[~2022-02-17 19:16 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-17 19:16 [PATCH libdrm v2 00/25] Update Tegra support Thierry Reding
2022-02-17 19:16 ` [PATCH libdrm v2 01/25] tegra: Indent according to .editorconfig Thierry Reding
2022-02-17 19:16 ` [PATCH libdrm v2 02/25] tegra: Remove unused IOCTL implementations Thierry Reding
2022-02-24 16:52 ` Dmitry Osipenko
2022-02-17 19:16 ` Thierry Reding [this message]
2022-02-17 19:16 ` [PATCH libdrm v2 04/25] tegra: Fix mmap() of GEM buffer objects Thierry Reding
2022-02-17 19:16 ` [PATCH libdrm v2 05/25] tegra: Add flink helpers Thierry Reding
2022-02-24 17:18 ` Dmitry Osipenko
2022-02-17 20:02 ` [PATCH libdrm v2 00/25] Update Tegra support Dmitry Osipenko
2022-02-17 21:37 ` Thierry Reding
2022-02-18 14:16 ` Dmitry Osipenko
2022-02-18 19:49 ` Dmitry Osipenko
2022-02-18 9:31 ` Mikko Perttunen
2022-02-21 20:29 ` Dmitry Osipenko
2022-02-22 8:41 ` Mikko Perttunen
2022-02-23 15:01 ` Thierry Reding
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220217191625.2534521-4-thierry.reding@gmail.com \
--to=thierry.reding@gmail.com \
--cc=digetx@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-tegra@vger.kernel.org \
--cc=mirq-linux@rere.qmqm.pl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).