From patchwork Mon Apr 30 16:56:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 10372127 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 99CF36038F for ; Mon, 30 Apr 2018 16:56:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BE6A28891 for ; Mon, 30 Apr 2018 16:56:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FC9E2889A; Mon, 30 Apr 2018 16:56:35 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 DEC5B28891 for ; Mon, 30 Apr 2018 16:56:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754844AbeD3Q4d (ORCPT ); Mon, 30 Apr 2018 12:56:33 -0400 Received: from foss.arm.com ([217.140.101.70]:39282 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753508AbeD3Q4d (ORCPT ); Mon, 30 Apr 2018 12:56:33 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C0F65F; Mon, 30 Apr 2018 09:56:32 -0700 (PDT) Received: from e110467-lin.cambridge.arm.com (e110467-lin.cambridge.arm.com [10.1.210.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 01AE13F587; Mon, 30 Apr 2018 09:56:31 -0700 (PDT) From: Robin Murphy To: mchehab@kernel.org Cc: linux-media@vger.kernel.org, iommu@lists.linux-foundation.org Subject: [PATCH] media: videobuf-dma-sg: Fix dma_{sync,unmap}_sg() calls Date: Mon, 30 Apr 2018 17:56:28 +0100 Message-Id: <453f27adfa6563d43a17a57b37c9c7db36c2114b.1525107326.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.17.0.dirty 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 This reverts commit fc7f8fd42c2b934ac348995e0c530c917fc277d5. Whilst the rationale for the above commit was in general correct, i.e. that users *consuming* the DMA addresses should rely on sglen rather than num_pages, it has always been the case that the DMA API itself still requires that dma_{sync,unmap}_sg() are called with the original number of entries as passed to dma_map_sg(), not the number of mapped entries it returned. Thus the particular changes made in that patch were erroneous. At worst this might lead to data loss at the tail end of mapped buffers on non-coherent hardware, while at best it's an example of incorrect DMA API usage which has proven to mislead readers. Signed-off-by: Robin Murphy --- drivers/media/v4l2-core/videobuf-dma-sg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/media/v4l2-core/videobuf-dma-sg.c b/drivers/media/v4l2-core/videobuf-dma-sg.c index add2edb23eac..37550f81cc29 100644 --- a/drivers/media/v4l2-core/videobuf-dma-sg.c +++ b/drivers/media/v4l2-core/videobuf-dma-sg.c @@ -334,7 +334,7 @@ int videobuf_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma) if (!dma->sglen) return 0; - dma_unmap_sg(dev, dma->sglist, dma->sglen, dma->direction); + dma_unmap_sg(dev, dma->sglist, dma->nr_pages, dma->direction); vfree(dma->sglist); dma->sglist = NULL; @@ -581,7 +581,7 @@ static int __videobuf_sync(struct videobuf_queue *q, MAGIC_CHECK(mem->dma.magic, MAGIC_DMABUF); dma_sync_sg_for_cpu(q->dev, mem->dma.sglist, - mem->dma.sglen, mem->dma.direction); + mem->dma.nr_pages, mem->dma.direction); return 0; }