Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1542368

[RFC PATCH 2/4] staging: android: ion: Duplicate sg_table

Path csiph.com!news.redatomik.org!aioe.org!bofh.it!news.nic.it!robomod
From Laura Abbott <labbott@redhat.com>
Newsgroups linux.kernel
Subject [RFC PATCH 2/4] staging: android: ion: Duplicate sg_table
Date Thu, 15 Dec 2016 01:10:01 +0100
Message-ID <sOrMt-78L-7@gated-at.bofh.it> (permalink)
References <sOrMt-78L-9@gated-at.bofh.it>
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GbnAauOF03AyFmqytkix1QiOEDdVU+M+IEjKh+Dygsk=; b=n+nEkT6BcJcUHwYxtIxFidAeexrgBuQFaTL8SFInvAikgn+K5iGSXfLOfr0i1earzD gOKiuonzL8h4r4RMj7hlkv+YSLhkBPZNV2x22DK0cddSpn0FEoFlMk/3Umz17PRZdVlC KDJADwzEazAPfQ9GbAd/iTNZxGPdmF+5lW0yMMeaf07FoBaZuJM8+PQ9EL/vXzFyfKNo AcJ4L1DnWJWWiEff8KWTA9+x3Ca8M0WlikDjy1YAW1Sq/YiSduwJQ3R3K3hfaQ0dM0Xa fZC2CHrq28ZHBZxUiOxbu0P1RM6/BS/eDXzKwiqOpp0qiu76vjSC2EQZTK57c4Qyzr56 tF+g==
X-Gm-Message-State AKaTC03BoqeyB9NktHuHVsXDHd1H3VGJzym3yhwm2GAQ4+IJRezmX2MMw8xeNJCGeIdIJPTQ
X-Received by 10.55.6.12 with SMTP id 12mr87621431qkg.182.1481760474881; Wed, 14 Dec 2016 16:07:54 -0800 (PST)
X-Mailer git-send-email 2.7.4
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 66
Organization linux.* mail to news gateway
X-Original-Cc Laura Abbott <labbott@redhat.com>, romlem@google.com, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, linaro-mm-sig@lists.linaro.org, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, linux-arm-kernel@lists.infradead.org, Bryan Huntsman <bryanh@codeaurora.org>, pratikp@codeaurora.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, Brian Starkey <brian.starkey@arm.com>
X-Original-Date Wed, 14 Dec 2016 16:07:41 -0800
X-Original-Message-ID <1481760463-3515-3-git-send-email-labbott@redhat.com>
X-Original-References <1481760463-3515-1-git-send-email-labbott@redhat.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1542368

Show key headers only | View raw


Ion currently returns a single sg_table on each dma_map call. This is
incorrect for later usage.

Not-signed-off-by: Laura Abbott <labbott@redhat.com>
---
 drivers/staging/android/ion/ion.c | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
index 8dd0932..76b874a0 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -795,19 +795,49 @@ void ion_client_destroy(struct ion_client *client)
 }
 EXPORT_SYMBOL(ion_client_destroy);
 
+static struct sg_table *dup_sg_table(struct sg_table *table)
+{
+	struct sg_table *new_table;
+	int ret, i;
+	struct scatterlisg *sg, *new_sg;
+
+	new_table = kzalloc(sizeof(*new_table), GFP_KERNEL);
+	if (!new_table)
+		return ERR_PTR(-ENOMEM);
+
+	ret = sg_alloc_table(new_table, table->nents, GFP_KERNEL);
+	if (ret) {
+		kfree(table);
+		return ERR_PTR(-ENOMEM);
+	}
+
+	new_sg = new_table->sgl;
+	for_each_sg(table->sgl, sg, table->nents, i) {
+		memcpy(new_sg, sg, sizeof(*sg));
+		sg->dma_address = 0;
+		new_sg = sg_next(new_sg);
+	}
+
+	return new_table;
+}
+
+
 static struct sg_table *ion_map_dma_buf(struct dma_buf_attachment *attachment,
 					enum dma_data_direction direction)
 {
 	struct dma_buf *dmabuf = attachment->dmabuf;
 	struct ion_buffer *buffer = dmabuf->priv;
+	struct sg_table *table;
 
-	return buffer->sg_table;
+	return dup_sg_table(buffer->sg_table);
 }
 
 static void ion_unmap_dma_buf(struct dma_buf_attachment *attachment,
 			      struct sg_table *table,
 			      enum dma_data_direction direction)
 {
+	sg_free_table(table);
+	kfree(table);
 }
 
 struct ion_vma_list {
-- 
2.7.4

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

[RFC PATCH 2/4] staging: android: ion: Duplicate sg_table Laura Abbott <labbott@redhat.com> - 2016-12-15 01:10 +0100

csiph-web