From patchwork Tue Oct 2 14:27:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 1537591 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 DF952DFFAD for ; Tue, 2 Oct 2012 14:48:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BFED8A0AC3 for ; Tue, 2 Oct 2012 07:48:22 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by gabe.freedesktop.org (Postfix) with ESMTP id A92389F711 for ; Tue, 2 Oct 2012 07:30:22 -0700 (PDT) Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MB900EV3SA0IC00@mailout4.samsung.com> for dri-devel@lists.freedesktop.org; Tue, 02 Oct 2012 23:30:22 +0900 (KST) X-AuditID: cbfee61b-b7f2b6d000000f14-a2-506afa7daf3c Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id B4.B1.03860.D7AFA605; Tue, 02 Oct 2012 23:30:22 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MB9005A7S65K790@mmp2.samsung.com> for dri-devel@lists.freedesktop.org; Tue, 02 Oct 2012 23:30:21 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCHv9 21/25] v4l: vb2-dma-contig: add reference counting for a device from allocator context Date: Tue, 02 Oct 2012 16:27:32 +0200 Message-id: <1349188056-4886-22-git-send-email-t.stanislaws@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1349188056-4886-1-git-send-email-t.stanislaws@samsung.com> References: <1349188056-4886-1-git-send-email-t.stanislaws@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrEJMWRmVeSWpSXmKPExsVy+t9jQd26X1kBBte/sFhc+fqezYHR4373 caYAxigum5TUnMyy1CJ9uwSujGOrlrIXrOWpmPd+FmMD4wKuLkZODgkBE4lD214wQ9hiEhfu rWfrYuTiEBKYzihx7ehqVghnHZPEy8ZJLCBVbEAdx5Z8ZgSxRQQcJE7fncUMUsQssIZZ4sXK G0DtHBzCAlkSP6aHgdSwCKhKXN8+kR0kzCvgIXH1nh/EMnmJp/f72EBsTqDwzycXwMYLCbhL 7FnexDaBkXcBI8MqRtHUguSC4qT0XCO94sTc4tK8dL3k/NxNjGCfP5PewbiqweIQowAHoxIP 766TmQFCrIllxZW5hxglOJiVRHit72cFCPGmJFZWpRblxxeV5qQWH2KU5mBREudt9kgJEBJI TyxJzU5NLUgtgskycXBKNTCGBa8U8dm14pJNt/yMPCYGhYw/XHd1WidmWrzaJ6falCj2L3vj hNvq2sWZV34I5IavnnAzOc2hY9OVFW8yj3/juZv+sXRfWa+JxZFVORsyXn66xxT9i7nxpTFH ygnpx9k6jJuW7hQ/9uS/+Tm27LOPGVeIpy24feLAmyC2Nf/YvT9d+9TgeMZPiaU4I9FQi7mo OBEAFe4ppPUBAAA= 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 --- drivers/media/video/videobuf2-dma-contig.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/media/video/videobuf2-dma-contig.c b/drivers/media/video/videobuf2-dma-contig.c index b138b5c..b4d287a 100644 --- a/drivers/media/video/videobuf2-dma-contig.c +++ b/drivers/media/video/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); } @@ -161,9 +162,13 @@ static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size) if (!buf) return ERR_PTR(-ENOMEM); + /* prevent the device from release while the buffer is exported */ + get_device(dev); + buf->vaddr = dma_alloc_coherent(dev, size, &buf->dma_addr, GFP_KERNEL); if (!buf->vaddr) { dev_err(dev, "dma_alloc_coherent of size %ld failed\n", size); + put_device(dev); kfree(buf); return ERR_PTR(-ENOMEM); }