From patchwork Thu Apr 13 07:57:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 9679183 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4255160326 for ; Thu, 13 Apr 2017 11:17:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3576E2860E for ; Thu, 13 Apr 2017 11:17:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 277F22862E; Thu, 13 Apr 2017 11:17:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B037B2860E for ; Thu, 13 Apr 2017 11:17:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3E5196E85F; Thu, 13 Apr 2017 11:17:09 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id B4C096E7E1 for ; Thu, 13 Apr 2017 07:58:03 +0000 (UTC) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Apr 2017 00:58:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.37,194,1488873600"; d="scan'208"; a="1155251056" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by fmsmga002.fm.intel.com with ESMTP; 13 Apr 2017 00:58:00 -0700 Received: from nauris.fi.intel.com (nauris.localdomain [192.168.240.2]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 4B91321279; Thu, 13 Apr 2017 10:57:55 +0300 (EEST) Received: by nauris.fi.intel.com (Postfix, from userid 1000) id B8B1C201AB; Thu, 13 Apr 2017 10:57:20 +0300 (EEST) From: Sakari Ailus To: linux-media@vger.kernel.org Subject: [RFC v3 11/14] vb2: dma-contig: Add WARN_ON_ONCE() to check for potential bugs Date: Thu, 13 Apr 2017 10:57:16 +0300 Message-Id: <1492070239-21532-12-git-send-email-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1492070239-21532-1-git-send-email-sakari.ailus@linux.intel.com> References: <1492070239-21532-1-git-send-email-sakari.ailus@linux.intel.com> X-Mailman-Approved-At: Thu, 13 Apr 2017 11:17:04 +0000 Cc: daniel.vetter@ffwll.ch, dri-devel@lists.freedesktop.org, hverkuil@xs4all.nl, kyungmin.park@samsung.com, posciak@chromium.org, m.szyprowski@samsung.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The scatterlist should always be present when the cache would need to be flushed. Each buffer type has its own means to provide that. Add WARN_ON_ONCE() to check the scatterist exists. Signed-off-by: Sakari Ailus Acked-by: Hans Verkuil --- drivers/media/v4l2-core/videobuf2-dma-contig.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c index 6a707d3..2847fbf 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-contig.c +++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c @@ -120,7 +120,7 @@ static void vb2_dc_prepare(void *buf_priv) * DMABUF exporter will flush the cache for us; only USERPTR * and MMAP buffers with non-coherent memory will be flushed. */ - if (buf->attrs & DMA_ATTR_NON_CONSISTENT) + if (buf->attrs & DMA_ATTR_NON_CONSISTENT && !WARN_ON_ONCE(!sgt)) dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir); } @@ -134,7 +134,7 @@ static void vb2_dc_finish(void *buf_priv) * DMABUF exporter will flush the cache for us; only USERPTR * and MMAP buffers with non-coherent memory will be flushed. */ - if (buf->attrs & DMA_ATTR_NON_CONSISTENT) + if (buf->attrs & DMA_ATTR_NON_CONSISTENT && !WARN_ON_ONCE(!sgt)) dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir); } @@ -380,7 +380,7 @@ static int vb2_dc_dmabuf_ops_begin_cpu_access(struct dma_buf *dbuf, * DMABUF exporter will flush the cache for us; only USERPTR * and MMAP buffers with non-coherent memory will be flushed. */ - if (buf->attrs & DMA_ATTR_NON_CONSISTENT) + if (buf->attrs & DMA_ATTR_NON_CONSISTENT && !WARN_ON_ONCE(!sgt)) dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir); @@ -397,7 +397,7 @@ static int vb2_dc_dmabuf_ops_end_cpu_access(struct dma_buf *dbuf, * DMABUF exporter will flush the cache for us; only USERPTR * and MMAP buffers with non-coherent memory will be flushed. */ - if (buf->attrs & DMA_ATTR_NON_CONSISTENT) + if (buf->attrs & DMA_ATTR_NON_CONSISTENT && !WARN_ON_ONCE(!sgt)) dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir);