[linux-dvb] [RFC-final] videobuf tree

Trent Piepho xyzzy at speakeasy.org
Sun Oct 7 23:03:25 CEST 2007

On Sun, 7 Oct 2007, Mauro Carvalho Chehab wrote:
> I took a look at cx23885 code. It seems that there's a serious error on
> the way you're using cx23885_buffer there:
> cx23885-dvb.c:  return cx23885_buf_prepare(q, port, (struct
> cx23885_buffer*)vb, field);
> cx23885-dvb.c:  cx23885_buf_queue(port, (struct cx23885_buffer*)vb);
> cx23885-dvb.c:  cx23885_free_buffer(q, (struct cx23885_buffer*)vb);
> It seems that you are forcing videobuf_buffer to be cx23885_buffer. This
> is not right!
> This is what is defined on cx23885.h:
> struct cx23885_buffer {
>         /* common v4l buffer stuff -- must be first */
>         struct videobuf_buffer vb;

I'm not sure that it is competely wrong.  Say one has a cx23885_buffer that
contains a videobuf_buffer.  Now suppose you have a pointer to the
videobuf_buffer, and you want to get a pointer to the cx23885_buffer that
contains it.  What you should write is:

struct videobuf_buffer *vb = ...;
struct cx23885_buffer *buf = container_of(vb, struct cx23885_buffer, vb);

But since vb is the first field of the cx23885_buffer struct, the container_of
will turn into just '(struct cx23885_buffer *)(vb)'

This code in videobuf-dma-sg.c looks odd to me:

/* Allocated area consists on 3 parts:
        struct video_buffer
        struct <driver>_buffer (cx88_buffer, saa7134_buf, ...)
        struct videobuf_pci_sg_memory

static void *__videobuf_alloc(size_t size)
        struct videbuf_pci_sg_memory *mem;
        struct videobuf_buffer *vb;

        vb = kzalloc(size+sizeof(*mem),GFP_KERNEL);

        mem = vb->priv = ((char *)vb)+size;

What is 'size', is that the size of the driver buffer?  Shouldn't you be
allocating size + sizeof(*vb) + sizeof(*mem)?

Is there documentation for videobuf anywhere?  It doesn't look like any of
the videobuf functions have descriptions of that they do or what the
parameters are.

More information about the linux-dvb mailing list