From patchwork Wed Oct 10 14:46:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 1574511 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id 6B1ACDFB34 for ; Wed, 10 Oct 2012 15:18:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 42839A09E7 for ; Wed, 10 Oct 2012 08:18:38 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by gabe.freedesktop.org (Postfix) with ESMTP id 15D899E938 for ; Wed, 10 Oct 2012 08:01:39 -0700 (PDT) Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MBO00M2TN2FXZ20@mailout3.samsung.com> for dri-devel@lists.freedesktop.org; Thu, 11 Oct 2012 00:01:38 +0900 (KST) X-AuditID: cbfee61a-b7f726d000000ec7-0b-50758dd27724 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 55.0B.03783.2DD85705; Thu, 11 Oct 2012 00:01:38 +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 <0MBO002YDME0EC70@mmp1.samsung.com> for dri-devel@lists.freedesktop.org; Thu, 11 Oct 2012 00:01:38 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCHv10 21/26] v4l: vb2-dma-contig: add reference counting for a device from allocator context Date: Wed, 10 Oct 2012 16:46:40 +0200 Message-id: <1349880405-26049-22-git-send-email-t.stanislaws@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1349880405-26049-1-git-send-email-t.stanislaws@samsung.com> References: <1349880405-26049-1-git-send-email-t.stanislaws@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrMJMWRmVeSWpSXmKPExsVy+t9jAd1LvaUBBn2/hCyufH3P5sDocb/7 OFMAYxSXTUpqTmZZapG+XQJXxqUNdxkLVnBXXLi7grWBcStnFyMnh4SAicTF3tNMELaYxIV7 69m6GLk4hAQWMUq8/dPCDuGsY5J4ue8VWBUbUMexJZ8ZQWwRAQeJ03dnMYMUMQusYZZ4sfIG G0hCWCBb4nnfNWYQm0VAVeJr43KWLkYODl4BT4mWZd4Q2+Qlnt7vAyvnBApfmDcdrFxIwEPi //rNTBMYeRcwMqxiFE0tSC4oTkrPNdQrTswtLs1L10vOz93ECPb6M6kdjCsbLA4xCnAwKvHw ZkSVBAixJpYVV+YeYpTgYFYS4TX1KQ0Q4k1JrKxKLcqPLyrNSS0+xCjNwaIkztvskRIgJJCe WJKanZpakFoEk2Xi4JRqYBRdfsNM1X6DefEuDp5zs16xyvSbcATpbmvbvI5LNZFz1cGeY9/3 MqeyupU2sey4+sGm8LjZ4rsPnr2QlRNPXDvju9miT6+ZG94o5kkrPt5/pyZEZ4nvLn+7e0r/ k20mXXh34bl9x55/d07tFd3vEsaevO/94b630vcUKzl0JLN/9vK0+99zv6HEUpyRaKjFXFSc CAAgJhbv9gEAAA== Cc: t.stanislaws@samsung.com, s.nawrocki@samsung.com, pawel@osciak.com, mchehab@redhat.com, daniel.vetter@ffwll.ch, subashrp@gmail.com, linaro-mm-sig@lists.linaro.org, kyungmin.park@samsung.com, laurent.pinchart@ideasonboard.com, zhangfei.gao@gmail.com, airlied@redhat.com, remi@remlab.net, m.szyprowski@samsung.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org This patch adds taking reference to the device for MMAP buffers. Such buffers, may be exported using DMABUF mechanism. If the driver that created a queue is unloaded then the queue is released, the device might be released too. However, buffers cannot be released if they are referenced by DMABUF descriptor(s). The device pointer kept in a buffer must be valid for the whole buffer's lifetime. Therefore MMAP buffers should take a reference to the device to avoid risk of dangling pointers. Signed-off-by: Tomasz Stanislawski Acked-by: Hans Verkuil Acked-by: Laurent Pinchart --- drivers/media/v4l2-core/videobuf2-dma-contig.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c index b138b5c..2d661fd 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-contig.c +++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c @@ -148,6 +148,7 @@ static void vb2_dc_put(void *buf_priv) kfree(buf->sgt_base); } dma_free_coherent(buf->dev, buf->size, buf->vaddr, buf->dma_addr); + put_device(buf->dev); kfree(buf); } @@ -168,6 +169,9 @@ static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size) return ERR_PTR(-ENOMEM); } + /* prevent the device from release while the buffer is exported */ + get_device(dev); + buf->dev = dev; buf->size = size;