From patchwork Wed Oct 10 14:46:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 12115 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 1488424189 for ; Wed, 10 Oct 2012 14:50:48 +0000 (UTC) Received: from mail-ia0-f180.google.com (mail-ia0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 5391EA18F35 for ; Wed, 10 Oct 2012 14:50:47 +0000 (UTC) Received: by mail-ia0-f180.google.com with SMTP id f6so415601iag.11 for ; Wed, 10 Oct 2012 07:50:46 -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: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=OUNFMBt6wiGnIhWuGWSvx0Ifo0EIljHLsnE+YVUNy40=; b=engFfz2SyLQhklGGk/vlrNuyrdQ9+8tbniAxR6x5Oimso8sIETO3mVOeW0GXMDJkPg llQZCxJ6PshWHtdMs9U//ynkpa+f2HtBTGwpGqFndLCdLhXCRgUSkHmPA3j5fg3Vrx0/ qf9VmM0haxP7nTcRQun/A7+7WKVihJ5FvqVEtHpaYn9dHabc9B6eGatJ5Z4XrhA9Ydvv t3WhWQv0g/MPrC1/TfJwHfr6ycjhdQb2SACwwHOyKiqFuVUm8mb7gyuW/y8l+wjrIQ0E ol6/xHo7NVVg/wjjI6ZQqEi0213HeEfzMfJn6vY/PZG6qd0YUx2TvqBXUlHe8s6Lv4px Rp7g== Received: by 10.50.87.134 with SMTP id ay6mr5438979igb.70.1349880646777; Wed, 10 Oct 2012 07:50:46 -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.67.148 with SMTP id n20csp235776igt; Wed, 10 Oct 2012 07:50:45 -0700 (PDT) Received: by 10.204.11.141 with SMTP id t13mr5220493bkt.65.1349880645199; Wed, 10 Oct 2012 07:50:45 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id gs13si2803805bkc.73.2012.10.10.07.50.43; Wed, 10 Oct 2012 07:50:45 -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 1TLxcQ-0001LB-VN; Wed, 10 Oct 2012 14:50:43 +0000 Received: from mailout2.samsung.com ([203.254.224.25]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TLxcO-0001L6-T6 for linaro-mm-sig@lists.linaro.org; Wed, 10 Oct 2012 14:50:41 +0000 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MBO00M8SMJZE160@mailout2.samsung.com> for linaro-mm-sig@lists.linaro.org; Wed, 10 Oct 2012 23:50:39 +0900 (KST) X-AuditID: cbfee61b-b7f2b6d000000f14-2b-50758b3f7caa Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 65.0B.03860.F3B85705; Wed, 10 Oct 2012 23:50:39 +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 linaro-mm-sig@lists.linaro.org; Wed, 10 Oct 2012 23:50:39 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Date: Wed, 10 Oct 2012 16:46:25 +0200 Message-id: <1349880405-26049-7-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+NgFnrCJMWRmVeSWpSXmKPExsVy+t9jAV377tIAg7W7TCy+XHnI5MDocfvf Y+YAxigum5TUnMyy1CJ9uwSujA03brEWrBGsuHF5MlsD43K+LkZODgkBE4lzL+ewQ9hiEhfu rWfrYuTiEBJYxCjxcu18RghnLZPEqn+nGEGq2IA6ji35DGaLCDhInL47ixmkiFlgDbPEi5U3 2EASwgIxEr/b7jKD2CwCqhJ3D50DW8Er4CGxedY+Voh18hJP7/eB1XMKeEpcmDcdrF4IqOb/ +s1MExh5FzAyrGIUTS1ILihOSs810itOzC0uzUvXS87P3cQI9vsz6R2MqxosDjEKcDAq8fBW ZJQECLEmlhVX5h5ilOBgVhLhNfUpDRDiTUmsrEotyo8vKs1JLT7EKM3BoiTO2+yREiAkkJ5Y kpqdmlqQWgSTZeLglGpgZFnE1CeaMdP9cQb39k3itdWmtmzn72+rKDr5Ied2wPmzjvxSvjkW u+WnRSdtd9OZldu67+drz7Zijb1Zs+NLPSeYRKWk3fshd2rbvhwBFY2yCWE3ZHQlpOpeO+zV mMW4KXxysJfg1XfOadPNfj2Pfa7yZ/OrI0f9Tlf7s+soNPR/f3g1Z1GCEktxRqKhFnNRcSIA ThuG8/cBAAA= Cc: k.debski@samsung.com, s.nawrocki@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, laurent.pinchart@ideasonboard.com, airlied@redhat.com, remi@remlab.net Subject: [Linaro-mm-sig] [PATCHv10 06/26] v4l: vb2-dma-contig: remove reference of alloc_ctx from a buffer 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: ALoCoQkUrVZRjUsyIzdadKjwBDTILsk2hdB2Hdykko35YPwVe2X0IIeeFTo/Zz34wEv4ple4Ie8K This patch removes a reference to alloc_ctx from an instance of a DMA contiguous buffer. It helps to avoid a risk of a dangling pointer if the context is released while the buffer is still valid. Moreover it removes one dereference step while accessing a device structure. Signed-off-by: Tomasz Stanislawski Signed-off-by: Kyungmin Park Acked-by: Laurent Pinchart Acked-by: Hans Verkuil --- drivers/media/v4l2-core/videobuf2-dma-contig.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c index a05784f..20c95da 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-contig.c +++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c @@ -23,7 +23,7 @@ struct vb2_dc_conf { }; struct vb2_dc_buf { - struct vb2_dc_conf *conf; + struct device *dev; void *vaddr; dma_addr_t dma_addr; unsigned long size; @@ -37,22 +37,21 @@ static void vb2_dc_put(void *buf_priv); static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size) { struct vb2_dc_conf *conf = alloc_ctx; + struct device *dev = conf->dev; struct vb2_dc_buf *buf; buf = kzalloc(sizeof *buf, GFP_KERNEL); if (!buf) return ERR_PTR(-ENOMEM); - buf->vaddr = dma_alloc_coherent(conf->dev, size, &buf->dma_addr, - GFP_KERNEL); + buf->vaddr = dma_alloc_coherent(dev, size, &buf->dma_addr, GFP_KERNEL); if (!buf->vaddr) { - dev_err(conf->dev, "dma_alloc_coherent of size %ld failed\n", - size); + dev_err(dev, "dma_alloc_coherent of size %ld failed\n", size); kfree(buf); return ERR_PTR(-ENOMEM); } - buf->conf = conf; + buf->dev = dev; buf->size = size; buf->handler.refcount = &buf->refcount; @@ -69,7 +68,7 @@ static void vb2_dc_put(void *buf_priv) struct vb2_dc_buf *buf = buf_priv; if (atomic_dec_and_test(&buf->refcount)) { - dma_free_coherent(buf->conf->dev, buf->size, buf->vaddr, + dma_free_coherent(buf->dev, buf->size, buf->vaddr, buf->dma_addr); kfree(buf); }