Skip to content

Commit

Permalink
[media] media: mx3_camera: buf_init() add buffer state check
Browse files Browse the repository at this point in the history
This patch checks the state of the buffer when calling .buf_init() method.
This is needed for the USERPTR buffer type, because in that case
.buf_init() is called every time a buffer is queued, and not only once
during the preparation stage, like in the MMAP case. Without this check
buffers get initialised repeatedly, which also leads to the allocation
of new DMA descriptors, of which there is only a final relatively small
number available. Both MMAP and USERPTR methods were successfully tested.

Signed-off-by: Alex Gershgorin <alexg@meprolight.com>
[g.liakhovetski@gmx.de: remove mx3_camera_buffer::state completely]
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
  • Loading branch information
Alex Gershgorin authored and Mauro Carvalho Chehab committed Aug 15, 2012
1 parent be0c44f commit 1690d86
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions drivers/media/video/mx3_camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,9 @@

#define MAX_VIDEO_MEM 16

enum csi_buffer_state {
CSI_BUF_NEEDS_INIT,
CSI_BUF_PREPARED,
};

struct mx3_camera_buffer {
/* common v4l buffer stuff -- must be first */
struct vb2_buffer vb;
enum csi_buffer_state state;
struct list_head queue;

/* One descriptot per scatterlist (per frame) */
Expand Down Expand Up @@ -285,7 +279,7 @@ static void mx3_videobuf_queue(struct vb2_buffer *vb)
goto error;
}

if (buf->state == CSI_BUF_NEEDS_INIT) {
if (!buf->txd) {
sg_dma_address(sg) = vb2_dma_contig_plane_dma_addr(vb, 0);
sg_dma_len(sg) = new_size;

Expand All @@ -298,7 +292,6 @@ static void mx3_videobuf_queue(struct vb2_buffer *vb)
txd->callback_param = txd;
txd->callback = mx3_cam_dma_done;

buf->state = CSI_BUF_PREPARED;
buf->txd = txd;
} else {
txd = buf->txd;
Expand Down Expand Up @@ -385,7 +378,6 @@ static void mx3_videobuf_release(struct vb2_buffer *vb)

/* Doesn't hurt also if the list is empty */
list_del_init(&buf->queue);
buf->state = CSI_BUF_NEEDS_INIT;

if (txd) {
buf->txd = NULL;
Expand All @@ -405,13 +397,13 @@ static int mx3_videobuf_init(struct vb2_buffer *vb)
struct mx3_camera_dev *mx3_cam = ici->priv;
struct mx3_camera_buffer *buf = to_mx3_vb(vb);

/* This is for locking debugging only */
INIT_LIST_HEAD(&buf->queue);
sg_init_table(&buf->sg, 1);
if (!buf->txd) {
/* This is for locking debugging only */
INIT_LIST_HEAD(&buf->queue);
sg_init_table(&buf->sg, 1);

buf->state = CSI_BUF_NEEDS_INIT;

mx3_cam->buf_total += vb2_plane_size(vb, 0);
mx3_cam->buf_total += vb2_plane_size(vb, 0);
}

return 0;
}
Expand Down

0 comments on commit 1690d86

Please sign in to comment.