From patchwork Mon Jul 23 23:07:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 10211 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 6573223E56 for ; Mon, 23 Jul 2012 23:08:08 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id 17758A199DA for ; Mon, 23 Jul 2012 23:08:08 +0000 (UTC) Received: by ggnf1 with SMTP id f1so6405389ggn.11 for ; Mon, 23 Jul 2012 16:08:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :dkim-signature:sender:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=ZUMS0HGg5rgmrQErz4z/MH6v3xrrbmdG8z96O/yqPQQ=; b=IVa7KNiDFk3f8GLcERv6CG2R7e5I8PT0PughxmHHPJIQAfkJwM5ViN42fEJidG5czf MQW2WwUhOlFMNMM7lCUI0/wvV/QT20mISGngUFu4GUd8q2ph+3oIXtf2tbBJul9XeAOB +KkUk8HvGBhzEfRvc6V3tcOkkD43/rv4o4wJOuOCbAZFaB8ZCxst4kK8J2jZd0vQkQbV Kc5EeKjftxVvhP0lBr1y59Qqs8P8iFGAT86gPwrIAWknTfXw5xSW+Lg0E+w4hPsFTO17 qnHXbRzovCLqB56/FMFp7seaMmqZvLSZF/IlAg+u5GYghpJTEcytYP5bBLil1CJlM9tX eokA== Received: by 10.43.126.1 with SMTP id gu1mr10113656icc.6.1343084887194; Mon, 23 Jul 2012 16:08:07 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.153.7 with SMTP id i7csp63205ibw; Mon, 23 Jul 2012 16:08:06 -0700 (PDT) Received: by 10.182.149.105 with SMTP id tz9mr23398053obb.65.1343084885879; Mon, 23 Jul 2012 16:08:05 -0700 (PDT) Received: from mail-ob0-f178.google.com (mail-ob0-f178.google.com [209.85.214.178]) by mx.google.com with ESMTPS id r4si13432548obz.102.2012.07.23.16.08.05 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 Jul 2012 16:08:05 -0700 (PDT) Received-SPF: pass (google.com: domain of robdclark@gmail.com designates 209.85.214.178 as permitted sender) client-ip=209.85.214.178; Authentication-Results: mx.google.com; spf=pass (google.com: domain of robdclark@gmail.com designates 209.85.214.178 as permitted sender) smtp.mail=robdclark@gmail.com; dkim=pass header.i=@gmail.com Received: by obbwd20 with SMTP id wd20so13778742obb.37 for ; Mon, 23 Jul 2012 16:08:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=ZUMS0HGg5rgmrQErz4z/MH6v3xrrbmdG8z96O/yqPQQ=; b=w17ux9Sadt72VPOwPkUWmfJ7R03Dp9lIb2MGH5CufThicfH4HXDccO088EKfMGnWJ+ aK+WoVBDZVo7Rn0SupOBaUioRLV3hcZ1YzVIUKY2EX7eDdry1HK2y7kUZxCN+ynUTrdn hhXowcD74f85LyLQspSD7T74neVYgKZ1Mer15GaDGl5cNzH9WznQLxxeSUTTkMUQB+kB F07/CyVv10eEa1vTTla2BsQeAE1x5OIu2+v8y7mQOIErBszXjqdI68pw+qqsqhtXrBMc oyfzIHzCuLUOWXYvtVwNF7SWm0s9UB2mvMB8D6W7FhBuBhw9KEUSOV9BQ2bNvVsZf4cb hnFw== Received: by 10.60.171.135 with SMTP id au7mr23807976oec.62.1343084885667; Mon, 23 Jul 2012 16:08:05 -0700 (PDT) Received: from localhost (ppp-70-129-143-140.dsl.rcsntx.swbell.net. [70.129.143.140]) by mx.google.com with ESMTPS id e9sm8340369oee.12.2012.07.23.16.08.04 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 Jul 2012 16:08:05 -0700 (PDT) Sender: Rob Clark From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: patches@linaro.org, Rob Clark Subject: [PATCH] drm/prime: drop reference on imported dma-buf Date: Mon, 23 Jul 2012 18:07:48 -0500 Message-Id: <1343084868-13427-1-git-send-email-rob.clark@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Gm-Message-State: ALoCoQlPZ8DsjN+CRJkX9Z2Y/Nxze1xTAx+Pyc8A4mRyTJ3WAUK9qT4TpHuc2nbUP+2cdzythoIC From: Rob Clark The GEM handle takes the reference. If a driver is actually importing a foreign dmabuf, rather than just re-importing it's own dmabuf, it needs to do a get_dma_buf(). Signed-off-by: Rob Clark Reviewed-by: Daniel Vetter --- drivers/gpu/drm/drm_prime.c | 7 +++++++ drivers/gpu/drm/exynos/exynos_drm_dmabuf.c | 4 ++++ drivers/gpu/drm/i915/i915_gem_dmabuf.c | 4 ++++ drivers/gpu/drm/nouveau/nouveau_prime.c | 5 +++++ drivers/gpu/drm/radeon/radeon_prime.c | 4 ++++ drivers/gpu/drm/udl/udl_gem.c | 4 ++++ 6 files changed, 28 insertions(+) diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index 4f80374..088e018 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -185,6 +185,13 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev, mutex_unlock(&file_priv->prime.lock); drm_gem_object_unreference_unlocked(obj); + /* + * Drop the ref we obtained w/ dma_buf_get() for the benefit of + * drivers simply re-importing their own dma-buf.. if drivers + * import a foreign dma-buf, they should get_dma_buf(). + */ + dma_buf_put(dma_buf); + return 0; fail: diff --git a/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c b/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c index f270790..f8ac75b 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +++ b/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c @@ -190,6 +190,9 @@ struct drm_gem_object *exynos_dmabuf_prime_import(struct drm_device *drm_dev, } } + /* since we are attaching, we need to hold a ref */ + get_dma_buf(dma_buf); + attach = dma_buf_attach(dma_buf, drm_dev->dev); if (IS_ERR(attach)) return ERR_PTR(-EINVAL); @@ -250,6 +253,7 @@ err_unmap_attach: dma_buf_unmap_attachment(attach, sgt, DMA_BIDIRECTIONAL); err_buf_detach: dma_buf_detach(dma_buf, attach); + dma_buf_put(dma_buf); return ERR_PTR(ret); } diff --git a/drivers/gpu/drm/i915/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/i915_gem_dmabuf.c index cf6bdec..9d2b2eb 100644 --- a/drivers/gpu/drm/i915/i915_gem_dmabuf.c +++ b/drivers/gpu/drm/i915/i915_gem_dmabuf.c @@ -189,6 +189,9 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev, } } + /* since we are attaching, we need to hold a ref */ + get_dma_buf(dma_buf); + /* need to attach */ attach = dma_buf_attach(dma_buf, dev->dev); if (IS_ERR(attach)) @@ -224,5 +227,6 @@ fail_unmap: dma_buf_unmap_attachment(attach, sg, DMA_BIDIRECTIONAL); fail_detach: dma_buf_detach(dma_buf, attach); + dma_buf_put(dma_buf); return ERR_PTR(ret); } diff --git a/drivers/gpu/drm/nouveau/nouveau_prime.c b/drivers/gpu/drm/nouveau/nouveau_prime.c index 4c82801..fc30886 100644 --- a/drivers/gpu/drm/nouveau/nouveau_prime.c +++ b/drivers/gpu/drm/nouveau/nouveau_prime.c @@ -200,6 +200,10 @@ struct drm_gem_object *nouveau_gem_prime_import(struct drm_device *dev, } } } + + /* since we are attaching, we need to hold a ref */ + get_dma_buf(dma_buf); + /* need to attach */ attach = dma_buf_attach(dma_buf, dev->dev); if (IS_ERR(attach)) @@ -223,6 +227,7 @@ fail_unmap: dma_buf_unmap_attachment(attach, sg, DMA_BIDIRECTIONAL); fail_detach: dma_buf_detach(dma_buf, attach); + dma_buf_put(dma_buf); return ERR_PTR(ret); } diff --git a/drivers/gpu/drm/radeon/radeon_prime.c b/drivers/gpu/drm/radeon/radeon_prime.c index 28f79ac..073a8d3 100644 --- a/drivers/gpu/drm/radeon/radeon_prime.c +++ b/drivers/gpu/drm/radeon/radeon_prime.c @@ -195,6 +195,9 @@ struct drm_gem_object *radeon_gem_prime_import(struct drm_device *dev, } } + /* since we are attaching, we need to hold a ref */ + get_dma_buf(dma_buf); + /* need to attach */ attach = dma_buf_attach(dma_buf, dev->dev); if (IS_ERR(attach)) @@ -218,5 +221,6 @@ fail_unmap: dma_buf_unmap_attachment(attach, sg, DMA_BIDIRECTIONAL); fail_detach: dma_buf_detach(dma_buf, attach); + dma_buf_put(dma_buf); return ERR_PTR(ret); } diff --git a/drivers/gpu/drm/udl/udl_gem.c b/drivers/gpu/drm/udl/udl_gem.c index 7bd65bd..47f25d5 100644 --- a/drivers/gpu/drm/udl/udl_gem.c +++ b/drivers/gpu/drm/udl/udl_gem.c @@ -305,6 +305,9 @@ struct drm_gem_object *udl_gem_prime_import(struct drm_device *dev, struct udl_gem_object *uobj; int ret; + /* since we are attaching, we need to hold a ref */ + get_dma_buf(dma_buf); + /* need to attach */ attach = dma_buf_attach(dma_buf, dev->dev); if (IS_ERR(attach)) @@ -329,5 +332,6 @@ fail_unmap: dma_buf_unmap_attachment(attach, sg, DMA_BIDIRECTIONAL); fail_detach: dma_buf_detach(dma_buf, attach); + dma_buf_put(dma_buf); return ERR_PTR(ret); }