Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp843876pxb; Tue, 3 Nov 2020 14:11:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJySgNODr1y53lutocguyANhEivw/Cj4NSeYOCLbTqKUOQt7OtEUTdkb/7rsAuAvmyfwZX65 X-Received: by 2002:a17:906:3958:: with SMTP id g24mr21364310eje.360.1604441467239; Tue, 03 Nov 2020 14:11:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604441467; cv=none; d=google.com; s=arc-20160816; b=IbnBEax0qfwaSAIx+8PqX+pnevjUsXYOEJ82IOsDmq5OTO1lHLhuZOSoU+V/RrlJje oxNXPyTCM7v1KPx0mtz5Vyx1bl9aF0hG0zhMZxWNcl2OT2CIO2cyiIOsDow5yLHD+Z0j MGClL/+CIoPL7EmclTLUrL+WAnWF7a/VoJ4esUQ6IWeIBRnfJQt9J0zEWtxFFo4hb0c3 OtONL8FGglOonwi6f9vrEnCIMXZ6bPLK3ED2zIckwZJLzAkGqNo/B1iT54OQeEbBeH++ 4R19jr9G9ul/mYGJYPQ3fLRwv7ZubNhGwk8mGSPb4NJnxvbeeDtme7JXcnnDl29YCCQv CEUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Vkdh63nDHTsisStawbP2VNuNjOsKp9FSwGWRzV2XMAU=; b=u6mKk3Rr6iMEmDfiLY8ZlRQVUce9lzpD7xlTXfL6mBfA30BFC6XV0+F1p/vnLr90Ph OlRYUtMuidQsFzUe1+VvYdjc8anR94wMpuSzcv1/2GKrvxI/vanUhAQdaxKWwPJnOqky 8LFAVQumHELwGJ9Q6SqqmTkkwLlRTrW+w19lJZmTfSthndodAkFjBlIJ8SXImoTp8gIz pRJtCe0G8je9bDhLLCHM364ZzCtEjolDQNyJu7+v2bkoBPqJGn2ZFJtS3NNcfMBICKWl XG7EIG0zWDKFyUCCo9cmz8BJm4ABReZ2m3F8CmoowMvMWGZpJ5xth6K8++c5cfQ8JhBn EVZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eXtokk1z; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d12si62087ejj.33.2020.11.03.14.10.44; Tue, 03 Nov 2020 14:11:07 -0800 (PST) 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=@kernel.org header.s=default header.b=eXtokk1z; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730276AbgKCWIW (ORCPT + 99 others); Tue, 3 Nov 2020 17:08:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:52580 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730283AbgKCUk7 (ORCPT ); Tue, 3 Nov 2020 15:40:59 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AF91D2236F; Tue, 3 Nov 2020 20:40:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436059; bh=1Zc1tCm91g0MUJ110dg27weTLVqabCHYe5mB8PO9XFs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eXtokk1ztjm3dC+DTb4vFktwhQIiVMhUv5VdkDLTiegWDp8W+gp+xZQdAsFVmyRls bNKla5Bj7TTQ+gPYiW8bm2Uu+B5lPriNeZmO9IKULs3wo2H2yHuiE2g3Vz4iWFgyxV 9VRwsxphHiIOiC81Iq/SKGk7inEOKQbB81Ci+38g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marek Szyprowski , Sasha Levin Subject: [PATCH 5.9 085/391] misc: fastrpc: fix common struct sg_table related issues Date: Tue, 3 Nov 2020 21:32:16 +0100 Message-Id: <20201103203352.772415780@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203348.153465465@linuxfoundation.org> References: <20201103203348.153465465@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marek Szyprowski [ Upstream commit 7cd7edb89437457ec36ffdbb970cc314d00c4aba ] The Documentation/DMA-API-HOWTO.txt states that the dma_map_sg() function returns the number of the created entries in the DMA address space. However the subsequent calls to the dma_sync_sg_for_{device,cpu}() and dma_unmap_sg must be called with the original number of the entries passed to the dma_map_sg(). struct sg_table is a common structure used for describing a non-contiguous memory buffer, used commonly in the DRM and graphics subsystems. It consists of a scatterlist with memory pages and DMA addresses (sgl entry), as well as the number of scatterlist entries: CPU pages (orig_nents entry) and DMA mapped pages (nents entry). It turned out that it was a common mistake to misuse nents and orig_nents entries, calling DMA-mapping functions with a wrong number of entries or ignoring the number of mapped entries returned by the dma_map_sg() function. To avoid such issues, lets use a common dma-mapping wrappers operating directly on the struct sg_table objects and use scatterlist page iterators where possible. This, almost always, hides references to the nents and orig_nents entries, making the code robust, easier to follow and copy/paste safe. Signed-off-by: Marek Szyprowski Link: https://lore.kernel.org/r/20200826063316.23486-29-m.szyprowski@samsung.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/misc/fastrpc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 7939c55daceb2..9d68677493163 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -518,7 +518,7 @@ fastrpc_map_dma_buf(struct dma_buf_attachment *attachment, table = &a->sgt; - if (!dma_map_sg(attachment->dev, table->sgl, table->nents, dir)) + if (!dma_map_sgtable(attachment->dev, table, dir, 0)) return ERR_PTR(-ENOMEM); return table; @@ -528,7 +528,7 @@ static void fastrpc_unmap_dma_buf(struct dma_buf_attachment *attach, struct sg_table *table, enum dma_data_direction dir) { - dma_unmap_sg(attach->dev, table->sgl, table->nents, dir); + dma_unmap_sgtable(attach->dev, table, dir, 0); } static void fastrpc_release(struct dma_buf *dmabuf) -- 2.27.0