From: Dan Carpenter <dan.carpenter@linaro.org>
To: Rob Clark <robdclark@chromium.org>
Cc: "Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Christian König" <christian.koenig@amd.com>,
"Dmitry Osipenko" <dmitry.osipenko@collabora.com>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: [PATCH next] drm/syncobj: Fix leak in drm_syncobj_import_sync_file_fence()
Date: Thu, 10 Apr 2025 19:25:57 +0300 [thread overview]
Message-ID: <c715ef30-9d91-46f3-8a0f-1039f3d25e7d@stanley.mountain> (raw)
We need to cleanup if the chain = dma_fence_chain_alloc() allocation
fails. Now that we have multiple error returns in this function, switch
to using an unwind ladder for cleanup.
Fixes: c2d3a7300695 ("drm/syncobj: Extend EXPORT_SYNC_FILE for timeline syncobjs")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
drivers/gpu/drm/drm_syncobj.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index 636cd83ca29e..c136d0c772dc 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -745,21 +745,24 @@ static int drm_syncobj_import_sync_file_fence(struct drm_file *file_private,
{
struct dma_fence *fence = sync_file_get_fence(fd);
struct drm_syncobj *syncobj;
+ int ret;
if (!fence)
return -EINVAL;
syncobj = drm_syncobj_find(file_private, handle);
if (!syncobj) {
- dma_fence_put(fence);
- return -ENOENT;
+ ret = -ENOENT;
+ goto err_put_fence;
}
if (point) {
struct dma_fence_chain *chain = dma_fence_chain_alloc();
- if (!chain)
- return -ENOMEM;
+ if (!chain) {
+ ret = -ENOMEM;
+ goto err_put_syncobj;
+ }
drm_syncobj_add_point(syncobj, chain, fence, point);
} else {
@@ -769,6 +772,13 @@ static int drm_syncobj_import_sync_file_fence(struct drm_file *file_private,
dma_fence_put(fence);
drm_syncobj_put(syncobj);
return 0;
+
+err_put_syncobj:
+ drm_syncobj_put(syncobj);
+err_put_fence:
+ dma_fence_put(fence);
+
+ return ret;
}
static int drm_syncobj_export_sync_file(struct drm_file *file_private,
--
2.47.2
next reply other threads:[~2025-04-10 16:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-10 16:25 Dan Carpenter [this message]
2025-04-10 22:06 ` Rob Clark
2025-04-11 13:25 ` Christian König
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=c715ef30-9d91-46f3-8a0f-1039f3d25e7d@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=airlied@gmail.com \
--cc=christian.koenig@amd.com \
--cc=dmitry.osipenko@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=robdclark@chromium.org \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
/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
all inboxes | Powered by JetHome®