diff mbox series

media: videobuf2: always set buffer vb2 pointer

Message ID 20210928034634.333785-1-senozhatsky@chromium.org (mailing list archive)
State New, archived
Headers show
Series media: videobuf2: always set buffer vb2 pointer | expand

Commit Message

Sergey Senozhatsky Sept. 28, 2021, 3:46 a.m. UTC
We need to always link allocated vb2_dc_buf back to vb2_buffer because
we dereference vb2 in prepare() and finish() callbacks.

Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
 drivers/media/common/videobuf2/videobuf2-dma-contig.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Chen-Yu Tsai Sept. 28, 2021, 6:24 a.m. UTC | #1
On Tue, Sep 28, 2021 at 2:16 PM Sergey Senozhatsky
<senozhatsky@chromium.org> wrote:
>
> We need to always link allocated vb2_dc_buf back to vb2_buffer because
> we dereference vb2 in prepare() and finish() callbacks.
>
> Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>

This fixes the breakage from the "videobuf2: support new noncontiguous DMA
API" series on the RK3399 Scarlet if the ChromeOS patch that changes
min_buffers_needed to 0 [1] is not applied.

Since there are other in-tree drivers that have min_buffers_needed=0,
I would recommend getting some more testing.

ChenYu

[1] https://crrev.com/c/3168489
Chen-Yu Tsai Sept. 28, 2021, 7:53 a.m. UTC | #2
On Tue, Sep 28, 2021 at 2:24 PM Chen-Yu Tsai <wenst@chromium.org> wrote:
>
> On Tue, Sep 28, 2021 at 2:16 PM Sergey Senozhatsky
> <senozhatsky@chromium.org> wrote:
> >
> > We need to always link allocated vb2_dc_buf back to vb2_buffer because
> > we dereference vb2 in prepare() and finish() callbacks.
> >
> > Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
>
> This fixes the breakage from the "videobuf2: support new noncontiguous DMA
> API" series on the RK3399 Scarlet if the ChromeOS patch that changes
> min_buffers_needed to 0 [1] is not applied.
>
> Since there are other in-tree drivers that have min_buffers_needed=0,
> I would recommend getting some more testing.

Seems I had a stale kernel when testing the min_buffers_needed=0 case.

Everythings works now.

Tested-by: Chen-Yu Tsai <wenst@chromium.org>
Tomasz Figa Oct. 5, 2021, 9:57 a.m. UTC | #3
On Tue, Sep 28, 2021 at 12:46 PM Sergey Senozhatsky
<senozhatsky@chromium.org> wrote:
>
> We need to always link allocated vb2_dc_buf back to vb2_buffer because
> we dereference vb2 in prepare() and finish() callbacks.
>
> Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
> ---
>  drivers/media/common/videobuf2/videobuf2-dma-contig.c | 3 +++
>  1 file changed, 3 insertions(+)
>

Acked-by: Tomasz Figa <tfiga@chromium.org>

Best regards,
Tomasz

> diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> index b052a4e36961..38767791955d 100644
> --- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> +++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> @@ -600,6 +600,7 @@ static void *vb2_dc_get_userptr(struct vb2_buffer *vb, struct device *dev,
>
>         buf->dev = dev;
>         buf->dma_dir = vb->vb2_queue->dma_dir;
> +       buf->vb = vb;
>
>         offset = lower_32_bits(offset_in_page(vaddr));
>         vec = vb2_create_framevec(vaddr, size);
> @@ -788,6 +789,8 @@ static void *vb2_dc_attach_dmabuf(struct vb2_buffer *vb, struct device *dev,
>                 return ERR_PTR(-ENOMEM);
>
>         buf->dev = dev;
> +       buf->vb = vb;
> +
>         /* create attachment for the dmabuf with the user device */
>         dba = dma_buf_attach(dbuf, buf->dev);
>         if (IS_ERR(dba)) {
> --
> 2.33.0.685.g46640cef36-goog
>
Sergey Senozhatsky Oct. 12, 2021, 1:57 a.m. UTC | #4
On (21/10/05 18:57), Tomasz Figa wrote:
> 
> On Tue, Sep 28, 2021 at 12:46 PM Sergey Senozhatsky
> <senozhatsky@chromium.org> wrote:
> >
> > We need to always link allocated vb2_dc_buf back to vb2_buffer because
> > we dereference vb2 in prepare() and finish() callbacks.
> >
> > Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
> > ---
> >  drivers/media/common/videobuf2/videobuf2-dma-contig.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> 
> Acked-by: Tomasz Figa <tfiga@chromium.org>

Hans, can you please pick up this patch?
Hans Verkuil Oct. 12, 2021, 7:52 a.m. UTC | #5
On 12/10/2021 03:57, Sergey Senozhatsky wrote:
> On (21/10/05 18:57), Tomasz Figa wrote:
>>
>> On Tue, Sep 28, 2021 at 12:46 PM Sergey Senozhatsky
>> <senozhatsky@chromium.org> wrote:
>>>
>>> We need to always link allocated vb2_dc_buf back to vb2_buffer because
>>> we dereference vb2 in prepare() and finish() callbacks.
>>>
>>> Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
>>> ---
>>>  drivers/media/common/videobuf2/videobuf2-dma-contig.c | 3 +++
>>>  1 file changed, 3 insertions(+)
>>>
>>
>> Acked-by: Tomasz Figa <tfiga@chromium.org>
> 
> Hans, can you please pick up this patch?
> 

Yes, it's already part of my upcoming pull request.

	Hans
diff mbox series

Patch

diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
index b052a4e36961..38767791955d 100644
--- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c
+++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
@@ -600,6 +600,7 @@  static void *vb2_dc_get_userptr(struct vb2_buffer *vb, struct device *dev,
 
 	buf->dev = dev;
 	buf->dma_dir = vb->vb2_queue->dma_dir;
+	buf->vb = vb;
 
 	offset = lower_32_bits(offset_in_page(vaddr));
 	vec = vb2_create_framevec(vaddr, size);
@@ -788,6 +789,8 @@  static void *vb2_dc_attach_dmabuf(struct vb2_buffer *vb, struct device *dev,
 		return ERR_PTR(-ENOMEM);
 
 	buf->dev = dev;
+	buf->vb = vb;
+
 	/* create attachment for the dmabuf with the user device */
 	dba = dma_buf_attach(dbuf, buf->dev);
 	if (IS_ERR(dba)) {