From patchwork Tue Oct 2 14:27:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 11927 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 791ED1A52FC for ; Tue, 2 Oct 2012 14:28:46 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 217E8A186F9 for ; Tue, 2 Oct 2012 14:28:46 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so14258231iej.11 for ; Tue, 02 Oct 2012 07:28:45 -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=0266fv9Sc6aUpkZktAZgz3BniPTE0uTGqlOvl/qFgXM=; b=i+FDzBswNpgh+w4MfoxWUM6JL8/yY3Z5DnvpRXVjQT5lGQSAfP1HANJbzi5Z/STqz3 hkLgJz6E0z4XsZAp5e0/4cOw+7Qswg6+VfWIDU/KvPXA7rP7IdUHFQLvVTarDrxJdBkp VhXtldhQ/3JINxA0IHssH7CE2udTtlal6g+JsNBlPywXpH49GgWD+6N2jGOLIuNASno+ j86irSc1/HIw/zaVA17V9oFsrFFL/wCa055rk4uH/B7w4PxT0OKtFXd9mL/sBNf4/vfH 92riNx8EUF6HE5UrYERHGIvFbifi8HeFoAH55zKkzyrTbe6G9aNWzBl876kY3AzB4pzE /FDQ== Received: by 10.42.110.130 with SMTP id q2mr14034302icp.53.1349188125915; Tue, 02 Oct 2012 07:28:45 -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.232 with SMTP id ex8csp84953igc; Tue, 2 Oct 2012 07:28:45 -0700 (PDT) Received: by 10.204.150.210 with SMTP id z18mr6750646bkv.53.1349188124195; Tue, 02 Oct 2012 07:28:44 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id hc2si1701309bkc.48.2012.10.02.07.28.43; Tue, 02 Oct 2012 07:28:44 -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 1TJ3Sk-0004a3-4H; Tue, 02 Oct 2012 14:28:42 +0000 Received: from mailout3.samsung.com ([203.254.224.33]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TJ3Si-0004Z4-5l for linaro-mm-sig@lists.linaro.org; Tue, 02 Oct 2012 14:28:40 +0000 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 <0MB9001EAS7O8CE0@mailout3.samsung.com> for linaro-mm-sig@lists.linaro.org; Tue, 02 Oct 2012 23:28:38 +0900 (KST) X-AuditID: cbfee61a-b7f726d000000ec7-eb-506afa16c474 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 68.8E.03783.61AFA605; Tue, 02 Oct 2012 23:28:38 +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 linaro-mm-sig@lists.linaro.org; Tue, 02 Oct 2012 23:28:38 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Date: Tue, 02 Oct 2012 16:27:17 +0200 Message-id: <1349188056-4886-7-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+NgFnrMJMWRmVeSWpSXmKPExsVy+t9jQV2xX1kBBnN3cVh8ufKQyYHR4/a/ x8wBjFFcNimpOZllqUX6dglcGWfaV7EXPBeo2Nv9kqmB8TlvFyMnh4SAicSlWV3sELaYxIV7 69m6GLk4hASmM0p83TSBCcJZyyRx+dsFJpAqNqCOY0s+M4LYIgIOEqfvzmIGKWIWWMMs8WLl DTaQhLBAtMSyKY/AbBYBVYl1dw4BreDg4BVwlzi4qRpim7zE0/t9YCWcAh4SP59cYAGxhYBK 9ixvYpvAyLuAkWEVo2hqQXJBcVJ6rqFecWJucWleul5yfu4mRrDXn0ntYFzZYHGIUYCDUYmH d+fJzAAh1sSy4srcQ4wSHMxKIrzW97MChHhTEiurUovy44tKc1KLDzFKc7AoifM2e6QECAmk J5akZqemFqQWwWSZODilGhjFzn2ZYRmUYhnn/L2sLrx1s5GX/P6vJx3mhLAfdXwYdnPF7M7X bfWbj0kuzE2fZDlzrcZ0w2rvM7OfrxGd0Tr7wNQNgQ0mzUWrWXfHeOurxCfdXBrYV7/1cN5v gU8i3oyKTSdySk6XFbLssm+zOfglce5y9tU/3/7Zc2xNk0yjQmFNCFvWRWUlluKMREMt5qLi RABaj+lq9gEAAA== 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] [PATCHv9 06/25] 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: ALoCoQkyWtzF2pXKPvaV6peL+07B52C4JgZT9szxnLI/Sh35uEY46QOE8L9Gtfm8w9F1NDhTN+cM 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 --- drivers/media/video/videobuf2-dma-contig.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/media/video/videobuf2-dma-contig.c b/drivers/media/video/videobuf2-dma-contig.c index a05784f..20c95da 100644 --- a/drivers/media/video/videobuf2-dma-contig.c +++ b/drivers/media/video/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); }