From patchwork Mon Sep 21 12:26:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "tiffany.lin" X-Patchwork-Id: 7229501 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8018ABEEC1 for ; Mon, 21 Sep 2015 12:27:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B67D72077A for ; Mon, 21 Sep 2015 12:27:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BDCEE20797 for ; Mon, 21 Sep 2015 12:27:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756484AbbIUM0q (ORCPT ); Mon, 21 Sep 2015 08:26:46 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:56728 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752699AbbIUM0p (ORCPT ); Mon, 21 Sep 2015 08:26:45 -0400 X-Listener-Flag: 11101 Received: from mtkhts07.mediatek.inc [(172.21.101.69)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 846516599; Mon, 21 Sep 2015 20:26:42 +0800 Received: from mtksdaap41.mediatek.inc (172.21.77.4) by mtkhts07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 14.3.181.6; Mon, 21 Sep 2015 20:26:40 +0800 From: Tiffany Lin To: Pawel Osciak , Marek Szyprowski , Kyungmin Park CC: Mauro Carvalho Chehab , Matthias Brugger , , , , , Tiffany Lin Subject: [RESEND PATCH] media: vb2: Fix vb2_dc_prepare do not correct sync data to device Date: Mon, 21 Sep 2015 20:26:11 +0800 Message-ID: <1442838371-21484-1-git-send-email-tiffany.lin@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty MIME-Version: 1.0 X-MTK: N Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP vb2_dc_prepare use the number of SG entries dma_map_sg_attrs return. But in dma_sync_sg_for_device, it use lengths of each SG entries before dma_map_sg_attrs. dma_map_sg_attrs will concatenate SGs until dma length > dma seg bundary. sgt->nents will less than sgt->orig_nents. Using SG entries after dma_map_sg_attrs in vb2_dc_prepare will make some SGs are not sync to device. After add DMA_ATTR_SKIP_CPU_SYNC in vb2_dc_get_userptr to remove sync data to device twice. Device randomly get incorrect data because some SGs are not sync to device. Change to use number of SG entries before dma_map_sg_attrs in vb2_dc_prepare to prevent this issue. Signed-off-by: Tiffany Lin Acked-by: Sakari Ailus --- drivers/media/v4l2-core/videobuf2-dma-contig.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c index 2397ceb..c5d00bd 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-contig.c +++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c @@ -100,7 +100,7 @@ static void vb2_dc_prepare(void *buf_priv) if (!sgt || buf->db_attach) return; - dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir); + dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir); } static void vb2_dc_finish(void *buf_priv) @@ -112,7 +112,7 @@ static void vb2_dc_finish(void *buf_priv) if (!sgt || buf->db_attach) return; - dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir); + dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir); } /*********************************************/