Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1258067pxx; Tue, 27 Oct 2020 12:02:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxPwNE8Gl9o7RRtLeiTeyGQWXgo37QfpEr7ms9cM3r8BOQfXijgmF+OBR3/dF+djemQ2ij X-Received: by 2002:a05:6402:4c6:: with SMTP id n6mr3870716edw.204.1603825340548; Tue, 27 Oct 2020 12:02:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603825340; cv=none; d=google.com; s=arc-20160816; b=n+qiSYkbNucIdlILFp1oQ/ldbfj7Ejjdlr6Yx8qthnnknzznW1bYuzwYeXL/N4/eAA g5O21jbdCWS1p1IPY7wKldZEg7ZfSWGLbXxLBRHA6M6FhtdlnRjhF7grb8KKRLe5qxeg 7QO0a3tU40O2QtT4JMl+/pt3lakIMmZ/FrO/OveqIpNVJCmyyhAdRO7jXtFR7WzJUQzA QuyqU96sOH3V/Z6DZMckqWm3YyhfCXNE13p7Lua29YFeM5u5TD3/yMcAEn7vcgEvUO2+ 2d0dzTzcx056JVZ1TjNlikfx3/w/IJfURPs/XL4RbK2C15N0rMaHgpmx3yFLtSudA+Vf 42zA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6Abtep9YWv0y1n0uEVnM5rqL3ksB5JIr2NVTdPs0Fo0=; b=TuzW9t5d5t1SaYZXSu8RjlSD7/5MjzfRanUogj1wKL+6U2jX/GGMY17XQlShiTIxpQ l3tNH5FqzsqJRgah9SWssNC6TtEK6sjkmqQz5ZviJLC009oy8FdPajwAnnMRBfDiS+9D rG/m4H8Mf/ipVZ6Po10OBk0Tw6zHu2UM9JyQDiCfn4gy7dK+akAf+OUAZZBpg/oGQEvy sZDLirmoOLkdwJoeCYL9Y4f3kZTql8a7OvQ8WNERaW9d4up4e4AEL3F4PoyUJ14ZUYV2 jbNQqlW2Xez1GZ3D5IxlLA9ti7iz5KCZPTfcED+qZeVZrVlI6HdgKmvzFwBrp2yBJFzR WcOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=stHEqP31; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l17si1532741eds.322.2020.10.27.12.01.57; Tue, 27 Oct 2020 12:02:20 -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=@kernel.org header.s=default header.b=stHEqP31; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2444445AbgJ0Aip (ORCPT + 99 others); Mon, 26 Oct 2020 20:38:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:48824 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408979AbgJZXuB (ORCPT ); Mon, 26 Oct 2020 19:50:01 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 857AA20878; Mon, 26 Oct 2020 23:50:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603756201; bh=Kfzq7AV37YFgA5ShnE9NH5z8uIFJ8H0nvzx2+znm3RU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=stHEqP312wJb5PWEAUbXR9x+N2LlWkkFPWkGiYsFzmLbqMrN1lEoOSO0m/levpgdG ljjnMfuCcMbhEwCM++3m4yqKmpoSrhFwtEi/wGTf+uHzeA6djmlyIGk3F69w4zYh0r wQbV+/RULEU/bOfFtZNymWfIjuKYbomcTQR60em4= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Marek Szyprowski , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL 5.9 044/147] misc: fastrpc: fix common struct sg_table related issues Date: Mon, 26 Oct 2020 19:47:22 -0400 Message-Id: <20201026234905.1022767-44-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201026234905.1022767-1-sashal@kernel.org> References: <20201026234905.1022767-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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.25.1