From patchwork Thu Aug 9 09:36:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 1299661 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 9DBB73FC23 for ; Thu, 9 Aug 2012 09:37:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757065Ab2HIJgq (ORCPT ); Thu, 9 Aug 2012 05:36:46 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:16903 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756475Ab2HIJgn (ORCPT ); Thu, 9 Aug 2012 05:36:43 -0400 Received: from epcpsbgm1.samsung.com (mailout4.samsung.com [203.254.224.34]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0M8H00CBPEOYWYV0@mailout4.samsung.com>; Thu, 09 Aug 2012 18:36:42 +0900 (KST) X-AuditID: cbfee61a-b7f616d000004b7e-04-502384aa5c98 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 1A.3A.19326.AA483205; Thu, 09 Aug 2012 18:36:42 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0M8H00KSJEOOS280@mmp1.samsung.com>; Thu, 09 Aug 2012 18:36:42 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Cc: airlied@redhat.com, m.szyprowski@samsung.com, t.stanislaws@samsung.com, kyungmin.park@samsung.com, laurent.pinchart@ideasonboard.com, sumit.semwal@linaro.org, inki.dae@samsung.com, daniel.vetter@ffwll.ch, rob@ti.com, pawel@osciak.com, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, jy0922.shim@samsung.com, sw0312.kim@samsung.com, dan.j.williams@intel.com, linux-doc@vger.kernel.org Subject: [PATCH v2 1/2] dma-buf: add reference counting for exporter module Date: Thu, 09 Aug 2012 11:36:21 +0200 Message-id: <1344504982-30415-2-git-send-email-t.stanislaws@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1344504982-30415-1-git-send-email-t.stanislaws@samsung.com> References: <1344504982-30415-1-git-send-email-t.stanislaws@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrNJMWRmVeSWpSXmKPExsVy+t9jAd1VLcoBBn+/iVgsbFvCYnF51xw2 i54NW1kdmD0+b5ILYIzisklJzcksSy3St0vgymiYf4ap4IlERf/vAywNjDNEuhg5OSQETCQu fn3MBGGLSVy4t56ti5GLQ0hgEaPE3daHrBBOF5PEuyn32ECq2IA6ji35zAhiiwg4SJy+O4sZ pIhZYCezxNFba4AcDg5hAW+JY42SICaLgKpE1x4/kHJeAQ+Jn61T2CGWyUs8vd8HNpJTwFNi 8erXzCC2EFDNrb4rTBMYeRcwMqxiFE0tSC4oTkrPNdQrTswtLs1L10vOz93ECA6CZ1I7GFc2 WBxiFOBgVOLh1digFCDEmlhWXJl7iFGCg1lJhPdWuXKAEG9KYmVValF+fFFpTmrxIUZpDhYl cV5j76/+QgLpiSWp2ampBalFMFkmDk6pBsZTu77U9TxQO5Me/K9+w2SbqI2hVxK7krJ3rdBu Viv53a3wvFry4amlLYLhM2O7GX5rPmI+2bspUvB2y5rngTmzZl+5EV9+m6e95fXhKzzzdgix P719bXpjddqswqr7Qj05h76eEcuTdJp83/HD/8tVxp2bdqQueebx4pvPsg9Hwz5JzdrZ1rBA iaU4I9FQi7moOBEABsViev4BAAA= X-TM-AS-MML: No Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This patch adds reference counting on a module that exported dma-buf and implements its operations. This prevents the module from being unloaded while DMABUF file is in use. Signed-off-by: Tomasz Stanislawski Acked-by: Sumit Semwal Acked-by: Daniel Vetter CC: linux-doc@vger.kernel.org --- Documentation/dma-buf-sharing.txt | 3 ++- drivers/base/dma-buf.c | 9 ++++++++- include/linux/dma-buf.h | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Documentation/dma-buf-sharing.txt b/Documentation/dma-buf-sharing.txt index ad86fb8..2613057 100644 --- a/Documentation/dma-buf-sharing.txt +++ b/Documentation/dma-buf-sharing.txt @@ -49,7 +49,8 @@ The dma_buf buffer sharing API usage contains the following steps: The buffer exporter announces its wish to export a buffer. In this, it connects its own private buffer data, provides implementation for operations that can be performed on the exported dma_buf, and flags for the file - associated with this buffer. + associated with this buffer. The operations structure has owner field. + You should initialize this to THIS_MODULE in most cases. Interface: struct dma_buf *dma_buf_export(void *priv, struct dma_buf_ops *ops, diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c index c30f3e1..a1d9cab 100644 --- a/drivers/base/dma-buf.c +++ b/drivers/base/dma-buf.c @@ -27,6 +27,7 @@ #include #include #include +#include static inline int is_dma_buf_file(struct file *); @@ -40,6 +41,7 @@ static int dma_buf_release(struct inode *inode, struct file *file) dmabuf = file->private_data; dmabuf->ops->release(dmabuf); + module_put(dmabuf->ops->owner); kfree(dmabuf); return 0; } @@ -105,9 +107,14 @@ struct dma_buf *dma_buf_export(void *priv, const struct dma_buf_ops *ops, return ERR_PTR(-EINVAL); } + if (!try_module_get(ops->owner)) + return ERR_PTR(-ENOENT); + dmabuf = kzalloc(sizeof(struct dma_buf), GFP_KERNEL); - if (dmabuf == NULL) + if (dmabuf == NULL) { + module_put(ops->owner); return ERR_PTR(-ENOMEM); + } dmabuf->priv = priv; dmabuf->ops = ops; diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index eb48f38..22953de 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -37,6 +37,7 @@ struct dma_buf_attachment; /** * struct dma_buf_ops - operations possible on struct dma_buf + * @owner: the module that implements dma_buf operations * @attach: [optional] allows different devices to 'attach' themselves to the * given buffer. It might return -EBUSY to signal that backing storage * is already allocated and incompatible with the requirements @@ -70,6 +71,7 @@ struct dma_buf_attachment; * @vunmap: [optional] unmaps a vmap from the buffer */ struct dma_buf_ops { + struct module *owner; int (*attach)(struct dma_buf *, struct device *, struct dma_buf_attachment *);