From patchwork Tue Aug 14 15:34:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 10749 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 C77EE23E00 for ; Tue, 14 Aug 2012 15:38:02 +0000 (UTC) Received: from mail-wg0-f48.google.com (mail-wg0-f48.google.com [74.125.82.48]) by fiordland.canonical.com (Postfix) with ESMTP id B9CD3A18539 for ; Tue, 14 Aug 2012 15:38:02 +0000 (UTC) Received: by mail-wg0-f48.google.com with SMTP id dq11so403389wgb.17 for ; Tue, 14 Aug 2012 08:38:02 -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:x-auditid :from:to:date:message-id:x-mailer:in-reply-to:references :x-brightmail-tracker:x-tm-as-mml:cc:subject:x-beenthere :x-mailman-version:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-gm-message-state; bh=dTJaOJKJ0SfUQJbs7HEDWe6rSGN27NHpim5RAeSQPkA=; b=nTjmwP3tRSUGGkIs14TgQUbR/7dP1kTb146HRy3KZyxipXG6QFvzd7SbhkiVHESRur mDdN13vW0RR2PXFV3iBP4hwIVBndM2alRSs3iTWzCdF9xd0KTMwOnSXEsmGJ2+z5bbfW TWkBBLBOVXDdBLfOo+t6Efg+a2m3ZUbJC2TCyruxFbfUBK4XLNzPjewCs83mS8EdFObA 45j1kHim2QLbaegtAMDYF04GmGG+fYlR+1vVZFRNbzJjvYOnS7QJUdKmGdZQ9gI+5c0K AbRsPTmYq1skeNs5iLZiyqLWAVmL8b6B3eEHijNmckzECtYyLpxzUgxRHNJtJkvw0t8i zuaA== Received: by 10.50.95.230 with SMTP id dn6mr12357684igb.16.1344958680676; Tue, 14 Aug 2012 08:38:00 -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.50.184.200 with SMTP id ew8csp20684igc; Tue, 14 Aug 2012 08:37:59 -0700 (PDT) Received: by 10.216.134.101 with SMTP id r79mr8411784wei.60.1344958679190; Tue, 14 Aug 2012 08:37:59 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id bu8si26704184wib.2.2012.08.14.08.37.57; Tue, 14 Aug 2012 08:37:59 -0700 (PDT) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1T1JBt-0008UI-1x; Tue, 14 Aug 2012 15:37:57 +0000 Received: from mailout3.samsung.com ([203.254.224.33]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1T1JBr-0008UC-OQ for linaro-mm-sig@lists.linaro.org; Tue, 14 Aug 2012 15:37:56 +0000 Received: from epcpsbgm2.samsung.com (mailout3.samsung.com [203.254.224.33]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0M8R00JPA4QZRJ20@mailout3.samsung.com> for linaro-mm-sig@lists.linaro.org; Wed, 15 Aug 2012 00:37:54 +0900 (KST) X-AuditID: cbfee61b-b7faf6d00000476a-0a-502a70d222c8 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 0D.1A.18282.2D07A205; Wed, 15 Aug 2012 00:37:54 +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 <0M8R004J44MBC810@mmp1.samsung.com> for linaro-mm-sig@lists.linaro.org; Wed, 15 Aug 2012 00:37:54 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Date: Tue, 14 Aug 2012 17:34:51 +0200 Message-id: <1344958496-9373-22-git-send-email-t.stanislaws@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1344958496-9373-1-git-send-email-t.stanislaws@samsung.com> References: <1344958496-9373-1-git-send-email-t.stanislaws@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrEJMWRmVeSWpSXmKPExsVy+t9jAd1LBVoBBne/Kll8ufKQyYHR4/a/ x8wBjFFcNimpOZllqUX6dglcGV+29LIVrOOp2LzetoFxIVcXIyeHhICJxJlrTYwQtpjEhXvr 2boYuTiEBBYxSjQ+fcQI4axlkrjfe5sFpIoNqOPYks9gHSICDhKn785iBiliFjjELLG/9zU7 SEJYIEvi07E5TCA2i4CqRPekD2DNvAIeEkc6ljNBrJOXeHq/jw3E5gSKv9zUDTSUA2ibu8TC n/4TGHkXMDKsYhRNLUguKE5KzzXSK07MLS7NS9dLzs/dxAj2+TPpHYyrGiwOMQpwMCrx8BYm agYIsSaWFVfmHmKU4GBWEuEtCtIKEOJNSaysSi3Kjy8qzUktPsQozcGiJM5r4v3VX0ggPbEk NTs1tSC1CCbLxMEp1cBobnWAe19zQ2rT1wY+57X2X5L3PYjtebAnbqbBa822CZICim4tHRLX hLimn1rcfLx0jW2XUdingxxHNp3vf3qQrbZps3Gywe/mOdOvnwiP+1Q559QxOa2Ny4ScTk1u 3G514xK7tLaXcsqPtQ8SbpjvutHUF2kpwH+5YEuQ4nGHugcayTHflV8osRRnJBpqMRcVJwIA jkMVGPUBAAA= X-TM-AS-MML: No Cc: k.debski@samsung.com, pawel@osciak.com, sumit.semwal@ti.com, mchehab@redhat.com, robdclark@gmail.com, linaro-mm-sig@lists.linaro.org, kyungmin.park@samsung.com, dmitriyz@google.com, laurent.pinchart@ideasonboard.com, s.nawrocki@samsung.com, airlied@redhat.com, remi@remlab.net, g.liakhovetski@gmx.de Subject: [Linaro-mm-sig] [PATCHv8 21/26] v4l: vb2-dma-contig: add reference counting for a device from allocator context X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQmxi2TFWk7GxVs2Tt1Eixjw5tIsMS4pdIY+E/LAK9CbiTrY6zsk0+4S/RNHFJKfzTES14h0 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 bb2b4ac8..d44766e 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); }