Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp871637pxx; Tue, 27 Oct 2020 02:33:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMsVcJxxzqYIe/qbvCjXc9djfKKpGLdmI4Dp2VJ7hB/SNY//G3HE3U4gvIs7IUMQbiQAnB X-Received: by 2002:a17:906:cb82:: with SMTP id mf2mr1407100ejb.435.1603791211138; Tue, 27 Oct 2020 02:33:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603791211; cv=none; d=google.com; s=arc-20160816; b=DouKFt9V+/TIBaKirHMtrWTVckJhef1sIjA4nhZsb6lViOdrdIHx6qtWni29yETGSP kDijLUdweLEilTL0h0RMWnUqA9juz6J/WbkO/8qjGWYUQlapAuIzyrRca54vZKrUer5E dZZr8Xo0Vv3d1bI735b8gj8DLWmQCE2HNZp7k5deVgJ04XS3wH/EPSC1lPpT4peZNtg8 DSzRwF8/csKJVVHWXyAIdPnvpwVycJ1YMWS7SDjH3pQpvNrx/QUiaF0c5D1jI2bwpxML ZzY2R8m17xplQB+qjkLt28p93mNkoxOiAnVr4w5a/zvNixQLMdJg5TFhMXECHm1XZJDe s6JQ== 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=zkNX0uG1+y8l1m4FRrVdX3gPak+v+UxVtNl5qvSvRzg=; b=IhC0gkHXzqlUJ364Tvw/0rRh4GSFrT93EIP7cm5FKr7hYUJRdHRzZugO1q1QONkfRZ AtK0PYr9t015wOYWyPITw61NuavdFf3IRMfJzAyndypi9oNGrGGnWX5cb70xFqm5EMMG /uzAWRAPJSQBkS4krYVUmadYRqP06i3/ChLPNySaDSWm4jpIo7JWbF4W5zeF/1u4ZyGG ZoOuAxmwWfcp+2vRORB63C8ncC10yzmhEAck0z+GEg1ikgqHlXCQcAO4lk20pTdSaKm+ MikJsFJkoh7wCZdVWWC+iBD4bM7oWx74y+McmPKcrwR6yUR4QxNFhwnaDoAFtY2G/b9G Cm+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="giX/b5Rl"; 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 qq26si605089ejb.103.2020.10.27.02.33.07; Tue, 27 Oct 2020 02:33:31 -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="giX/b5Rl"; 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 S2409262AbgJZXu7 (ORCPT + 99 others); Mon, 26 Oct 2020 19:50:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:49724 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2409099AbgJZXuW (ORCPT ); Mon, 26 Oct 2020 19:50:22 -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 C7FC721707; Mon, 26 Oct 2020 23:50:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603756221; bh=CtXkxi4z3ePz3347kCygJai6J6gCO1+WxDFYAEUk9so=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=giX/b5RloOfIOK0dEGdfXlPJVlbA31hCJNAJwjTnXraRC0CY4+Ecik+fnmAnhQ+2P HGftatvgOrF06dmCUdN1B4GDXFW4MdndJXEd5NnPR3+MgjP2+HKNrUxJ+5r64FhSVL c0WSqsnG3tk5wWFequ1VD8TB8DV8JANiJ+vQlTKw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Marek Szyprowski , Andrzej Hajda , Sasha Levin , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org Subject: [PATCH AUTOSEL 5.9 061/147] drm: exynos: fix common struct sg_table related issues Date: Mon, 26 Oct 2020 19:47:39 -0400 Message-Id: <20201026234905.1022767-61-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 84404614167b829f7b58189cd24b6c0c74897171 ] 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 Reviewed-by: Andrzej Hajda Acked-by : Inki Dae Signed-off-by: Sasha Levin --- drivers/gpu/drm/exynos/exynos_drm_g2d.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c b/drivers/gpu/drm/exynos/exynos_drm_g2d.c index 03be314271811..967a5cdc120e3 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c +++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c @@ -395,8 +395,8 @@ static void g2d_userptr_put_dma_addr(struct g2d_data *g2d, return; out: - dma_unmap_sg(to_dma_dev(g2d->drm_dev), g2d_userptr->sgt->sgl, - g2d_userptr->sgt->nents, DMA_BIDIRECTIONAL); + dma_unmap_sgtable(to_dma_dev(g2d->drm_dev), g2d_userptr->sgt, + DMA_BIDIRECTIONAL, 0); pages = frame_vector_pages(g2d_userptr->vec); if (!IS_ERR(pages)) { @@ -511,10 +511,10 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct g2d_data *g2d, g2d_userptr->sgt = sgt; - if (!dma_map_sg(to_dma_dev(g2d->drm_dev), sgt->sgl, sgt->nents, - DMA_BIDIRECTIONAL)) { + ret = dma_map_sgtable(to_dma_dev(g2d->drm_dev), sgt, + DMA_BIDIRECTIONAL, 0); + if (ret) { DRM_DEV_ERROR(g2d->dev, "failed to map sgt with dma region.\n"); - ret = -ENOMEM; goto err_sg_free_table; } -- 2.25.1