diff options
author | Tomasz Stanislawski <t.stanislaws@samsung.com> | 2012-08-07 12:19:49 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-11-25 14:21:20 -0500 |
commit | 67a5d0cebf30020bdc4846892adf360c57610268 (patch) | |
tree | 87bae9a35aa00d739455289abecc576ce36983b1 /drivers/media | |
parent | 9ef2cbeb819213520a8be77d4c3f7330a1a06ac5 (diff) |
[media] v4l: vb2-dma-contig: add reference counting for a device from allocator context
This patch adds taking reference to the device for MMAP buffers.
Such buffers, may be exported using DMABUF mechanism. If the driver that
created a queue is unloaded then the queue is released, the device might be
released too. However, buffers cannot be released if they are referenced by
DMABUF descriptor(s). The device pointer kept in a buffer must be valid for the
whole buffer's lifetime. Therefore MMAP buffers should take a reference to the
device to avoid risk of dangling pointers.
Signed-off-by: Tomasz Stanislawski <t.stanislaws@samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/v4l2-core/videobuf2-dma-contig.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c index 78c281c55ad7..b35f38e9f2d7 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-contig.c +++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c | |||
@@ -148,6 +148,7 @@ static void vb2_dc_put(void *buf_priv) | |||
148 | kfree(buf->sgt_base); | 148 | kfree(buf->sgt_base); |
149 | } | 149 | } |
150 | dma_free_coherent(buf->dev, buf->size, buf->vaddr, buf->dma_addr); | 150 | dma_free_coherent(buf->dev, buf->size, buf->vaddr, buf->dma_addr); |
151 | put_device(buf->dev); | ||
151 | kfree(buf); | 152 | kfree(buf); |
152 | } | 153 | } |
153 | 154 | ||
@@ -168,7 +169,8 @@ static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size) | |||
168 | return ERR_PTR(-ENOMEM); | 169 | return ERR_PTR(-ENOMEM); |
169 | } | 170 | } |
170 | 171 | ||
171 | buf->dev = dev; | 172 | /* Prevent the device from being released while the buffer is used */ |
173 | buf->dev = get_device(dev); | ||
172 | buf->size = size; | 174 | buf->size = size; |
173 | 175 | ||
174 | buf->handler.refcount = &buf->refcount; | 176 | buf->handler.refcount = &buf->refcount; |