From patchwork Fri Dec 16 01:24:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9477191 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 94A1160827 for ; Fri, 16 Dec 2016 01:24:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9057D28876 for ; Fri, 16 Dec 2016 01:24:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 85032288A7; Fri, 16 Dec 2016 01:24:26 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03574288A3 for ; Fri, 16 Dec 2016 01:24:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758303AbcLPBYQ (ORCPT ); Thu, 15 Dec 2016 20:24:16 -0500 Received: from galahad.ideasonboard.com ([185.26.127.97]:50169 "EHLO galahad.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756817AbcLPBYG (ORCPT ); Thu, 15 Dec 2016 20:24:06 -0500 Received: from avalon.bb.dnainternet.fi (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804]) by galahad.ideasonboard.com (Postfix) with ESMTPSA id 35E8720BB9; Fri, 16 Dec 2016 02:23:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1481851427; bh=UL+M7G3ADsMYVQBJbajNWZCmXtaPjXmd5Sb8i8krWus=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VMxYEiscRok03snx34A4v1yrevOK3cAg5PyLSEpFl5Uxd5Sn9x6MaNoCAzIFYOWp+ xWE/sR8o6Nhmeg49XpypR4u3LJeyUqjsuDQitn6O4H/OdSD4zKocy0GYbADzqxkkqH VVW/aiVMmvrPprlNBDmBnvi2KKG/UHfAMTG9krgg= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: dri-devel@lists.freedesktop.org, Pawel Osciak , Marek Szyprowski , Kyungmin Park , Hans Verkuil , Sumit Semwal , Rob Clark , Daniel Vetter , Laura Abbott , Sakari Ailus Subject: [RFC v2 11/11] vb2: dma-contig: Add WARN_ON_ONCE() to check for potential bugs Date: Fri, 16 Dec 2016 03:24:25 +0200 Message-Id: <20161216012425.11179-12-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161216012425.11179-1-laurent.pinchart+renesas@ideasonboard.com> References: <20161216012425.11179-1-laurent.pinchart+renesas@ideasonboard.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sakari Ailus 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 --- drivers/media/v4l2-core/videobuf2-dma-contig.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c index a0e88ad93f07..9409f458cf89 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-contig.c +++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c @@ -122,6 +122,9 @@ static void vb2_dc_prepare(void *buf_priv) if (!(buf->attrs & DMA_ATTR_NON_CONSISTENT)) return; + if (WARN_ON_ONCE(!sgt)) + return; + dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir); } @@ -138,6 +141,9 @@ static void vb2_dc_finish(void *buf_priv) if (!(buf->attrs & DMA_ATTR_NON_CONSISTENT)) return; + if (WARN_ON_ONCE(!sgt)) + return; + dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir); }