Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp462564ybj; Tue, 5 May 2020 01:49:52 -0700 (PDT) X-Google-Smtp-Source: APiQypLq6sTqBezwrSo2GT3ZpE49RQGA/uzhaegD+m9lgJUiYy1yX0k08zQamX77BQnXLU1UnFYv X-Received: by 2002:a17:906:ce49:: with SMTP id se9mr1590097ejb.345.1588668591965; Tue, 05 May 2020 01:49:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588668591; cv=none; d=google.com; s=arc-20160816; b=W50EhPYPUkLfqogbIOUNfptKEVEuwy35EQO16CDQjTRyOLYfIbW/SpVK3WAIIH1kn6 nCCUXWVOv24g+b1LN3NPpD8HBbm69ktJdH6CwtrFbyCTGXtZ3G5+h80ElAkktTgopRrb GJQ8PZAdwxUxXGRi5PwKL7lCJbNJ+cuJQWzgiHH6M0/5EP1iXovglPT3RfAwvdSxysC2 hQPtnu0wx/2WvokocnI1TOpzRp/HN7+rCI9y3oDOU51SH+WnLvta2k/oO1F1/mlVf1YL QDHfWXMJEGXC28hXojM3DBA+z9PAhEZDFy1OYz0aSfW0qlF3G7N3znMburv9Nqe96yl3 CBHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=4Wn9PB2hsUcfeXjKsNb4RnLI8IycXO7vRARzqAzX/lM=; b=NcgyHzpdNn2VHB9V9neTGcSvjT1KaTJ01E3TU80pYEintzsy4W2ZctVgtN0XNBimxo h/LWC8reTPadr85VNrquMNiKJq6ZZD9P0D7EsJYaKykHAK/JOEDgYPlCfM0pUwEN68pV k8miFAOiLP6A0yv48/Z9CbnllT/UQq+2Xp5FKYln0Q4lOQXCc4Z4djZUaHKCrtJb8RKJ 9VDIaQYEn4M/x5x0DH9oW9BwaWCLr+pgjIbzRZ1xCDxCkcN2LrgALIcITmpeUr3FPIZq Vg+qkKkJUomoZXAqQJWJDDTms9VblBcV2+iEkPdSATwLWH6WRi/AQDrlIsEIJ9hWAITo r3Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=JwfIevFg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p26si726954ejd.193.2020.05.05.01.49.29; Tue, 05 May 2020 01:49:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=JwfIevFg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728814AbgEEIrJ (ORCPT + 99 others); Tue, 5 May 2020 04:47:09 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:52098 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728712AbgEEIqk (ORCPT ); Tue, 5 May 2020 04:46:40 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200505084637euoutp02997b3dc9de0c577fe941a49e8106f7ba~MFX2WNtTI2638126381euoutp02Z for ; Tue, 5 May 2020 08:46:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200505084637euoutp02997b3dc9de0c577fe941a49e8106f7ba~MFX2WNtTI2638126381euoutp02Z DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1588668397; bh=4Wn9PB2hsUcfeXjKsNb4RnLI8IycXO7vRARzqAzX/lM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JwfIevFgE6xjUpKZC6gcYgjqm046UpBiV8zsSnO2IcDLts8JMUwbQ745BuJH9qLTG CqpLwL88vxE0DnOoJf51DLOolbai2fFIiwepI2UqB+FIPJkyEa/RYoft4/pKr8ryp5 c9zNdqxTI2PVpUBZrHmPN7CvDGYJbnI+v5R3D/HI= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200505084637eucas1p2ae80f76e35086405a44f4510d0ab7e90~MFX1t_H5f1348613486eucas1p2m; Tue, 5 May 2020 08:46:37 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id E2.11.60698.CE721BE5; Tue, 5 May 2020 09:46:36 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200505084636eucas1p23a33d0b83ca284692713745d004f93ea~MFX1XHA9E2336923369eucas1p2C; Tue, 5 May 2020 08:46:36 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200505084636eusmtrp12bf7c85bfcea14cc0211d23f25f7de34~MFX1WPsxX0942509425eusmtrp1Z; Tue, 5 May 2020 08:46:36 +0000 (GMT) X-AuditID: cbfec7f5-a29ff7000001ed1a-4a-5eb127ecdc90 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 0F.14.08375.CE721BE5; Tue, 5 May 2020 09:46:36 +0100 (BST) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200505084635eusmtip1a40af7250cf41dbed0f1cc43f8041929~MFX0pbEfv0686606866eusmtip1N; Tue, 5 May 2020 08:46:35 +0000 (GMT) From: Marek Szyprowski To: dri-devel@lists.freedesktop.org, iommu@lists.linux-foundation.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org Cc: Marek Szyprowski , Christoph Hellwig , Robin Murphy , Bartlomiej Zolnierkiewicz , linux-arm-kernel@lists.infradead.org, David Airlie , Daniel Vetter , Dmitry Osipenko , Mauro Carvalho Chehab , Greg Kroah-Hartman , Thierry Reding , Jonathan Hunter , linux-media@vger.kernel.org, linux-tegra@vger.kernel.org, devel@driverdev.osuosl.org Subject: [PATCH v3 21/25] staging: tegra-vde: fix common struct sg_table related issues Date: Tue, 5 May 2020 10:46:10 +0200 Message-Id: <20200505084614.30424-21-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200505084614.30424-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0WSe0hTYRjG+3bOzo7D6WlWfqkoDLIMvKHBJ1Z2++PYHxVoUULW1IOXvLGj lkIk2cWWEy+UOsqGlpp3l2mZl7wsC2XUFFmpM1uKltnFu8zKddT++73P+z48Dx8fiYnH+HZk ZGwCI4uVRksIId7waknrOrWzLtjjT44PUmjf8FBdfg0f/WnIxlBz77IAVfw0AtQ/951AacU1 BHpcoeEhVZsvuqYswtFs/ygPqY0DfNTXdI9AGbVP+ejWrJJAVV3DAlSiNvFQ+4/PfLTUVIgf sKErCysBbWjtxOmWeRVOP1cOC2h1+S2Cbpz/yKfb7lcK6JHb3Tz6ycMr9OBvI0bn6ksB/eJ9 KkEr0qYJOrO+HNAzascT1kHCvWFMdGQSI3Pff14YUfXJJIjXWl6q0+9NBe+EcmBBQsobaoY0 PDOLqTIAO5UuciBc5VkAW1IHMG6YAbB3wSBYd+gLfmKcoxTAstxdG465NAPfvCAoTyj/JifM vIW6DuBrhaWZMaoXh72LXnJAkjbUGThykzXLOLUDjjw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3mEBsXgE7iSv35zJDbJCXWL3hAJjNCRR/fOkO1LZCiQ/nv7NO YORbwMiwilEktbQ4Nz232FCvODG3uDQvXS85P3cTIzAatx37uXkH46WNwYcYBTgYlXh4Iz6v jxNiTSwrrsw9xCjBwawkwrvsx4Y4Id6UxMqq1KL8+KLSnNTiQ4ymQEdNZJYSTc4HJoq8knhD U0NzC0tDc2NzYzMLJXHeDoGDMUIC6YklqdmpqQWpRTB9TBycUg2Muko3RMovvHki7CHA3+LV 7JCau4xtg73btAuWW48ZWEicnCnP/519GeOWfb9Wsj02qxK81xllLrHgo3t/gEJfRcCcyv6H /23nKvBUrmv7OVvh6qei/jlc/i5ugmxx5pIbNM9MlTusXBU369HrZCk/BqMK0zLna7puT278 Ov6w1HjxEQONbfFKLMUZiYZazEXFiQDIsp8b3AIAAA== X-CMS-MailID: 20200505084636eucas1p23a33d0b83ca284692713745d004f93ea X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200505084636eucas1p23a33d0b83ca284692713745d004f93ea X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200505084636eucas1p23a33d0b83ca284692713745d004f93ea References: <20200505083926.28503-1-m.szyprowski@samsung.com> <20200505084614.30424-1-m.szyprowski@samsung.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The Documentation/DMA-API-HOWTO.txt states that dma_map_sg returns the numer of the created entries in the DMA address space. However the subsequent calls to dma_sync_sg_for_{device,cpu} and dma_unmap_sg must be called with the original number of the entries passed to dma_map_sg. The sg_table->nents in turn holds the result of the dma_map_sg call as stated in include/linux/scatterlist.h. A common mistake was to ignore a result of the dma_map_sg function and don't use the sg_table->orig_nents at all. To avoid such issues, lets use common dma-mapping wrappers operating directly on the struct sg_table objects and adjust references to the nents and orig_nents respectively. Signed-off-by: Marek Szyprowski --- For more information, see '[PATCH v3 00/25] DRM: fix struct sg_table nents vs. orig_nents misuse' thread: https://lkml.org/lkml/2020/5/5/187 --- drivers/staging/media/tegra-vde/iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/staging/media/tegra-vde/iommu.c b/drivers/staging/media/tegra-vde/iommu.c index 6af863d..adf8dc7 100644 --- a/drivers/staging/media/tegra-vde/iommu.c +++ b/drivers/staging/media/tegra-vde/iommu.c @@ -36,8 +36,8 @@ int tegra_vde_iommu_map(struct tegra_vde *vde, addr = iova_dma_addr(&vde->iova, iova); - size = iommu_map_sg(vde->domain, addr, sgt->sgl, sgt->nents, - IOMMU_READ | IOMMU_WRITE); + size = iommu_map_sgtable(vde->domain, addr, sgt, + IOMMU_READ | IOMMU_WRITE); if (!size) { __free_iova(&vde->iova, iova); return -ENXIO; -- 1.9.1