aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Stanislawski <t.stanislaws@samsung.com>2012-06-14 09:37:40 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-11-25 14:11:43 -0500
commit72f86bffbc59de76458cb8c3981df12e059b71fc (patch)
treeedd1e9c99caa51327fc5232842d7d52077295ace
parentf7f129ce2e33f9bd444c1889216ab92f2ec69d91 (diff)
[media] v4l: vb2-dma-contig: remove reference of alloc_ctx from a buffer
This patch removes a reference to alloc_ctx from an instance of a DMA contiguous buffer. It helps to avoid a risk of a dangling pointer if the context is released while the buffer is still valid. Moreover it removes one dereference step while accessing a device structure. Signed-off-by: Tomasz Stanislawski <t.stanislaws@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Tested-by: Mauro Carvalho Chehab <mchehab@redhat.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/v4l2-core/videobuf2-dma-contig.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c
index a05784ffe271..20c95da7aa77 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
@@ -23,7 +23,7 @@ struct vb2_dc_conf {
23}; 23};
24 24
25struct vb2_dc_buf { 25struct vb2_dc_buf {
26 struct vb2_dc_conf *conf; 26 struct device *dev;
27 void *vaddr; 27 void *vaddr;
28 dma_addr_t dma_addr; 28 dma_addr_t dma_addr;
29 unsigned long size; 29 unsigned long size;
@@ -37,22 +37,21 @@ static void vb2_dc_put(void *buf_priv);
37static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size) 37static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size)
38{ 38{
39 struct vb2_dc_conf *conf = alloc_ctx; 39 struct vb2_dc_conf *conf = alloc_ctx;
40 struct device *dev = conf->dev;
40 struct vb2_dc_buf *buf; 41 struct vb2_dc_buf *buf;
41 42
42 buf = kzalloc(sizeof *buf, GFP_KERNEL); 43 buf = kzalloc(sizeof *buf, GFP_KERNEL);
43 if (!buf) 44 if (!buf)
44 return ERR_PTR(-ENOMEM); 45 return ERR_PTR(-ENOMEM);
45 46
46 buf->vaddr = dma_alloc_coherent(conf->dev, size, &buf->dma_addr, 47 buf->vaddr = dma_alloc_coherent(dev, size, &buf->dma_addr, GFP_KERNEL);
47 GFP_KERNEL);
48 if (!buf->vaddr) { 48 if (!buf->vaddr) {
49 dev_err(conf->dev, "dma_alloc_coherent of size %ld failed\n", 49 dev_err(dev, "dma_alloc_coherent of size %ld failed\n", size);
50 size);
51 kfree(buf); 50 kfree(buf);
52 return ERR_PTR(-ENOMEM); 51 return ERR_PTR(-ENOMEM);
53 } 52 }
54 53
55 buf->conf = conf; 54 buf->dev = dev;
56 buf->size = size; 55 buf->size = size;
57 56
58 buf->handler.refcount = &buf->refcount; 57 buf->handler.refcount = &buf->refcount;
@@ -69,7 +68,7 @@ static void vb2_dc_put(void *buf_priv)
69 struct vb2_dc_buf *buf = buf_priv; 68 struct vb2_dc_buf *buf = buf_priv;
70 69
71 if (atomic_dec_and_test(&buf->refcount)) { 70 if (atomic_dec_and_test(&buf->refcount)) {
72 dma_free_coherent(buf->conf->dev, buf->size, buf->vaddr, 71 dma_free_coherent(buf->dev, buf->size, buf->vaddr,
73 buf->dma_addr); 72 buf->dma_addr);
74 kfree(buf); 73 kfree(buf);
75 } 74 }