From patchwork Fri Apr 15 05:10:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Airlie X-Patchwork-Id: 8844911 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D0696C0553 for ; Fri, 15 Apr 2016 05:11:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0227D2037E for ; Fri, 15 Apr 2016 05:11:12 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 473122037F for ; Fri, 15 Apr 2016 05:11:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9004C6E114; Fri, 15 Apr 2016 05:11:04 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by gabe.freedesktop.org (Postfix) with ESMTPS id C9F326E114 for ; Fri, 15 Apr 2016 05:10:57 +0000 (UTC) Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8377DC0586C8 for ; Fri, 15 Apr 2016 05:10:57 +0000 (UTC) Received: from dreadlord-bne-redhat-com.bne.redhat.com (dhcp-40-179.bne.redhat.com [10.64.40.179]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3F5AlYm005176 for ; Fri, 15 Apr 2016 01:10:56 -0400 From: Dave Airlie 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 Message-Id: <1460697046-23781-10-git-send-email-airlied@gmail.com> In-Reply-To: <1460697046-23781-1-git-send-email-airlied@gmail.com> References: <1460697046-23781-1-git-send-email-airlied@gmail.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dave Airlie 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 --- 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; }