From: Dave Airlie <airlied@gmail.com>
To: dri-devel@lists.freedesktop.org
Subject: [PATCH 09/15] drm/modes: move reference taking into object lookup.
Date: Fri, 15 Apr 2016 15:10:40 +1000 [thread overview]
Message-ID: <1460697046-23781-10-git-send-email-airlied@gmail.com> (raw)
In-Reply-To: <1460697046-23781-1-git-send-email-airlied@gmail.com>
From: Dave Airlie <airlied@redhat.com>
When we lookup an ref counted object we now take a proper reference
using kref_get_unless_zero.
Framebuffer lookup no longer needs do this itself.
Convert rmfb to using framebuffer lookup and deal with the fact
it now gets an extra reference that we have to cleanup. This should
mean we can avoid holding fb_lock across rmfb. (if I'm wrong let me
know).
We also now only hold the fbs_lock around the list manipulation.
Signed-off-by: Dave Airlie <airlied@redhat.com>
---
drivers/gpu/drm/drm_crtc.c | 37 ++++++++++++++++++++-----------------
1 file changed, 20 insertions(+), 17 deletions(-)
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 21cb998..e47c4a2 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -364,6 +364,11 @@ static struct drm_mode_object *_object_find(struct drm_device *dev,
if (obj &&
obj->type == DRM_MODE_OBJECT_BLOB)
obj = NULL;
+
+ if (obj && obj->free_cb) {
+ if (!kref_get_unless_zero(&obj->refcount))
+ obj = NULL;
+ }
mutex_unlock(&dev->mode_config.idr_mutex);
return obj;
@@ -495,11 +500,8 @@ struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
mutex_lock(&dev->mode_config.fb_lock);
obj = _object_find(dev, id, DRM_MODE_OBJECT_FB);
- if (obj) {
+ if (obj)
fb = obj_to_fb(obj);
- if (!kref_get_unless_zero(&fb->base.refcount))
- fb = NULL;
- }
mutex_unlock(&dev->mode_config.fb_lock);
return fb;
@@ -3434,37 +3436,38 @@ int drm_mode_rmfb(struct drm_device *dev,
{
struct drm_framebuffer *fb = NULL;
struct drm_framebuffer *fbl = NULL;
- struct drm_mode_object *obj;
uint32_t *id = data;
int found = 0;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
+ fb = drm_framebuffer_lookup(dev, *id);
+ if (!fb)
+ return -ENOENT;
+
mutex_lock(&file_priv->fbs_lock);
- mutex_lock(&dev->mode_config.fb_lock);
- obj = _object_find(dev, *id, DRM_MODE_OBJECT_FB);
- if (!obj)
- goto fail_lookup;
- fb = obj_to_fb(obj);
list_for_each_entry(fbl, &file_priv->fbs, filp_head)
if (fb == fbl)
found = 1;
- if (!found)
- goto fail_lookup;
+ if (!found) {
+ mutex_unlock(&file_priv->fbs_lock);
+ goto fail_unref;
+ }
list_del_init(&fb->filp_head);
- mutex_unlock(&dev->mode_config.fb_lock);
mutex_unlock(&file_priv->fbs_lock);
+ /* we now own the reference that was stored in the fbs list */
drm_framebuffer_unreference(fb);
- return 0;
+ /* drop the reference we picked up in framebuffer lookup */
+ drm_framebuffer_unreference(fb);
-fail_lookup:
- mutex_unlock(&dev->mode_config.fb_lock);
- mutex_unlock(&file_priv->fbs_lock);
+ return 0;
+fail_unref:
+ drm_framebuffer_unreference(fb);
return -ENOENT;
}
--
2.5.5
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2016-04-15 5:10 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-15 5:10 drm reference counter connectors and fix lifetimes Dave Airlie
2016-04-15 5:10 ` [PATCH 01/15] drm/mode: rework drm_mode_object_put to drm_mode_object_unregister Dave Airlie
2016-04-21 8:03 ` Daniel Vetter
2016-04-15 5:10 ` [PATCH 02/15] drm/mode: move framebuffer_free up above framebuffer_init Dave Airlie
2016-04-21 8:03 ` Daniel Vetter
2016-04-15 5:10 ` [PATCH 03/15] drm/modes: drop __drm_framebuffer_unregister Dave Airlie
2016-04-21 8:05 ` Daniel Vetter
2016-04-15 5:10 ` [PATCH 04/15] drm/mode: introduce wrapper to read framebuffer refcount Dave Airlie
2016-04-21 8:07 ` Daniel Vetter
2016-04-15 5:10 ` [PATCH 05/15] drm/mode: move framebuffer reference into object Dave Airlie
2016-04-21 8:12 ` Daniel Vetter
2016-04-15 5:10 ` [PATCH 06/15] drm/mode: use _object_find to find framebuffers Dave Airlie
2016-04-21 8:14 ` Daniel Vetter
2016-04-15 5:10 ` [PATCH 07/15] drm/mode: reduce scope of fb_lock in framebuffer init Dave Airlie
2016-04-21 8:54 ` Daniel Vetter
2016-04-15 5:10 ` [PATCH 08/15] drm/mode: reduce lock hold in addfb2 Dave Airlie
2016-04-21 8:59 ` Daniel Vetter
2016-04-15 5:10 ` Dave Airlie [this message]
2016-04-21 9:05 ` [PATCH 09/15] drm/modes: move reference taking into object lookup Daniel Vetter
2016-04-15 5:10 ` [PATCH 10/15] drm/modes: reduce fb_lock to just protecting lists Dave Airlie
2016-04-21 9:06 ` Daniel Vetter
2016-04-15 5:10 ` [PATCH 11/15] drm/modes: stop handling framebuffer special Dave Airlie
2016-04-21 9:06 ` Daniel Vetter
2016-04-15 5:10 ` [PATCH 12/15] drm/modes: add connector reference counting Dave Airlie
2016-04-22 9:24 ` Daniel Vetter
2016-04-15 5:10 ` [PATCH 13/15] drm: take references to connectors used in a modeset Dave Airlie
2016-04-22 8:49 ` Daniel Vetter
2016-04-27 1:44 ` Dave Airlie
2016-04-15 5:10 ` [PATCH 14/15] drm/i915/mst: use reference counted connectors Dave Airlie
2016-04-22 9:03 ` Daniel Vetter
2016-04-27 1:54 ` Dave Airlie
2016-04-27 6:29 ` Daniel Vetter
2016-04-15 5:10 ` [PATCH 15/15] drm/radeon/dp_mst: use connector ref counting Dave Airlie
2016-04-22 9:04 ` Daniel Vetter
2016-04-21 9:08 ` drm reference counter connectors and fix lifetimes Daniel Vetter
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=1460697046-23781-10-git-send-email-airlied@gmail.com \
--to=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
/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).