5a0a59ced1a99e19d043c2be3f56303b5dcdf33c
[openwrt/staging/jow.git] /
1 From 118802c75e04a2f1b94245695076d2506f667ae7 Mon Sep 17 00:00:00 2001
2 From: Gurchetan Singh <gurchetansingh@chromium.org>
3 Date: Mon, 2 Dec 2019 17:36:26 -0800
4 Subject: [PATCH] udmabuf: separate out creating/destroying
5 scatter-table
6
7 Commit 17a7ce203490459cff14fb1c8f9a15d65fd1c544 upstream.
8
9 These are nice functions and can be re-used.
10
11 Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org>
12 Link: http://patchwork.freedesktop.org/patch/msgid/20191203013627.85991-3-gurchetansingh@chromium.org
13 Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
14 ---
15 drivers/dma-buf/udmabuf.c | 26 +++++++++++++++++++-------
16 1 file changed, 19 insertions(+), 7 deletions(-)
17
18 --- a/drivers/dma-buf/udmabuf.c
19 +++ b/drivers/dma-buf/udmabuf.c
20 @@ -47,10 +47,10 @@ static int mmap_udmabuf(struct dma_buf *
21 return 0;
22 }
23
24 -static struct sg_table *map_udmabuf(struct dma_buf_attachment *at,
25 - enum dma_data_direction direction)
26 +static struct sg_table *get_sg_table(struct device *dev, struct dma_buf *buf,
27 + enum dma_data_direction direction)
28 {
29 - struct udmabuf *ubuf = at->dmabuf->priv;
30 + struct udmabuf *ubuf = buf->priv;
31 struct sg_table *sg;
32 int ret;
33
34 @@ -62,7 +62,7 @@ static struct sg_table *map_udmabuf(stru
35 GFP_KERNEL);
36 if (ret < 0)
37 goto err;
38 - if (!dma_map_sg(at->dev, sg->sgl, sg->nents, direction)) {
39 + if (!dma_map_sg(dev, sg->sgl, sg->nents, direction)) {
40 ret = -EINVAL;
41 goto err;
42 }
43 @@ -74,13 +74,25 @@ err:
44 return ERR_PTR(ret);
45 }
46
47 +static void put_sg_table(struct device *dev, struct sg_table *sg,
48 + enum dma_data_direction direction)
49 +{
50 + dma_unmap_sg(dev, sg->sgl, sg->nents, direction);
51 + sg_free_table(sg);
52 + kfree(sg);
53 +}
54 +
55 +static struct sg_table *map_udmabuf(struct dma_buf_attachment *at,
56 + enum dma_data_direction direction)
57 +{
58 + return get_sg_table(at->dev, at->dmabuf, direction);
59 +}
60 +
61 static void unmap_udmabuf(struct dma_buf_attachment *at,
62 struct sg_table *sg,
63 enum dma_data_direction direction)
64 {
65 - dma_unmap_sg(at->dev, sg->sgl, sg->nents, direction);
66 - sg_free_table(sg);
67 - kfree(sg);
68 + return put_sg_table(at->dev, sg, direction);
69 }
70
71 static void release_udmabuf(struct dma_buf *buf)