From patchwork Tue Nov 3 20:32:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 320505 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp4948529ilc; Tue, 3 Nov 2020 14:08:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJwSbvDrY2nFGZsl+0yg1KHq+ZqvOjWXhidGg7ickz2GKGb3xhrq/w5EhVdDw4t50z3dSYJH X-Received: by 2002:a17:906:2b8d:: with SMTP id m13mr18119550ejg.536.1604441305352; Tue, 03 Nov 2020 14:08:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604441305; cv=none; d=google.com; s=arc-20160816; b=tCnQfa0aYEUzx9qusLah669LHZ/dBZTx4qnI3syOxW3KhD1jOzvmMbZcaxCVbEP5pp POntJ9JHhTPSFqvQ96PmTQs4jgd75RybNFiFrEodLKEPLX5g9sKfKwVuIhoBogB4/rZ5 akpdGEBjlptKjvjWhra1o0xEJCwEOKiomhyCN/4NmXD1+JzsQwIm7HSLdo3WwckdWRke pKxF0QNT24LoyqC951hiFpGEuW1PlrACNNjdI/EOaKWuhqrmjwiIPA7DW7GJkrkLbvh+ aPHxIhSWcynUawi/LAEd8PiWA0pzCFn2g630ttzD8xa/TX8v8NjIeFkMZk+eBMchZ9m/ ee0A== 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=BSV/4S7yMQin6GqjC62qpk7H44R9PXM2EUMC96eAl9j511vysCo9yLsc1ErGwCIF/h Te0FRosw7k7Fv4TqoSaP+YV2v3bZU0ejVWwUThzMQYD9b2Y351ub7VJRvp21pgHHjXGK kosRm6tK9dP0za2KyiKAkL2/41Mfo/fOocOUcbTfwbZ2yoGPxrzrgjV3FehwUiL9GrRJ L/o4ooEOjRoIqWhJhN3Q+o/dErsBUX50MHElA5oeWZ62kkSQgyM4n0Yk2D2l5Gy29Zar YORRGn/bj3cNyZQdmj+49w8YAi7ytxK8m4sckzkdOb2xUHB33TUxkwtImmmAKUlbVwuL n7NA== 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 stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 sb16si115711ejb.674.2020.11.03.14.08.25; Tue, 03 Nov 2020 14:08:25 -0800 (PST) Received-SPF: pass (google.com: domain of stable-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 stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S1730281AbgKCWIV (ORCPT + 15 others); Tue, 3 Nov 2020 17:08:21 -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 Precedence: bulk List-ID: X-Mailing-List: stable@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(-) -- 2.27.0 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)