diff mbox series

media: videobuf2: Fix IS_ERR checking in vb2_dc_put_userptr()

Message ID 20231003092329.3919828-1-make_ruc2021@163.com
State Superseded
Headers show
Series media: videobuf2: Fix IS_ERR checking in vb2_dc_put_userptr() | expand

Commit Message

Ma Ke Oct. 3, 2023, 9:23 a.m. UTC
In order to avoid error pointers from frame_vector_pages(), we could
use IS_ERR() to check the return value to fix this. This checking
operation could make sure that vector contains pages.

Signed-off-by: Ma Ke <make_ruc2021@163.com>
---
 .../media/common/videobuf2/videobuf2-dma-contig.c   | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Comments

Tomasz Figa Oct. 12, 2023, 6:19 a.m. UTC | #1
On Tue, Oct 3, 2023 at 6:23 PM Ma Ke <make_ruc2021@163.com> wrote:
>
> In order to avoid error pointers from frame_vector_pages(), we could
> use IS_ERR() to check the return value to fix this. This checking
> operation could make sure that vector contains pages.
>
> Signed-off-by: Ma Ke <make_ruc2021@163.com>
> ---
>  .../media/common/videobuf2/videobuf2-dma-contig.c   | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> index 2fa455d4a048..5001f2a258dd 100644
> --- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> +++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> @@ -542,13 +542,14 @@ static void vb2_dc_put_userptr(void *buf_priv)
>                  */
>                 dma_unmap_sgtable(buf->dev, sgt, buf->dma_dir,
>                                   DMA_ATTR_SKIP_CPU_SYNC);
> -               pages = frame_vector_pages(buf->vec);
> -               /* sgt should exist only if vector contains pages... */
> -               BUG_ON(IS_ERR(pages));
>                 if (buf->dma_dir == DMA_FROM_DEVICE ||
> -                   buf->dma_dir == DMA_BIDIRECTIONAL)
> -                       for (i = 0; i < frame_vector_count(buf->vec); i++)
> -                               set_page_dirty_lock(pages[i]);
> +                   buf->dma_dir == DMA_BIDIRECTIONAL){

Missing space between ) and { .

Otherwise:

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

Best regards,
Tomasz

> +                       pages = frame_vector_pages(buf->vec);
> +                       /* sgt should exist only if vector contains pages... */
> +                       if (!WARN_ON_ONCE(IS_ERR(pages)))
> +                               for (i = 0; i < frame_vector_count(buf->vec); i++)
> +                                       set_page_dirty_lock(pages[i]);
> +               }
>                 sg_free_table(sgt);
>                 kfree(sgt);
>         } else {
> --
> 2.37.2
>
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 2fa455d4a048..5001f2a258dd 100644
--- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c
+++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
@@ -542,13 +542,14 @@  static void vb2_dc_put_userptr(void *buf_priv)
 		 */
 		dma_unmap_sgtable(buf->dev, sgt, buf->dma_dir,
 				  DMA_ATTR_SKIP_CPU_SYNC);
-		pages = frame_vector_pages(buf->vec);
-		/* sgt should exist only if vector contains pages... */
-		BUG_ON(IS_ERR(pages));
 		if (buf->dma_dir == DMA_FROM_DEVICE ||
-		    buf->dma_dir == DMA_BIDIRECTIONAL)
-			for (i = 0; i < frame_vector_count(buf->vec); i++)
-				set_page_dirty_lock(pages[i]);
+		    buf->dma_dir == DMA_BIDIRECTIONAL){
+			pages = frame_vector_pages(buf->vec);
+			/* sgt should exist only if vector contains pages... */
+			if (!WARN_ON_ONCE(IS_ERR(pages)))
+				for (i = 0; i < frame_vector_count(buf->vec); i++)
+					set_page_dirty_lock(pages[i]);
+		}
 		sg_free_table(sgt);
 		kfree(sgt);
 	} else {