[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20e3745b-ed89-4f9e-9ef6-f527122fe204@xs4all.nl>
Date: Mon, 2 Oct 2023 12:16:36 +0200
From: Hans Verkuil <hverkuil@...all.nl>
To: Ma Ke <make_ruc2021@....com>, tfiga@...omium.org,
m.szyprowski@...sung.com, mchehab@...nel.org
Cc: linux-media@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] media: videobuf2: Fix IS_ERR checking in
vb2_vmalloc_put_userptr()
Hi Ma Ke,
On 24/09/2023 14:44, Ma Ke 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@....com>
> ---
> drivers/media/common/videobuf2/videobuf2-vmalloc.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/media/common/videobuf2/videobuf2-vmalloc.c b/drivers/media/common/videobuf2/videobuf2-vmalloc.c
> index 7c635e292106..c37775080aff 100644
> --- a/drivers/media/common/videobuf2/videobuf2-vmalloc.c
> +++ b/drivers/media/common/videobuf2/videobuf2-vmalloc.c
> @@ -134,6 +134,7 @@ static void vb2_vmalloc_put_userptr(void *buf_priv)
> if (!buf->vec->is_pfns) {
> n_pages = frame_vector_count(buf->vec);
> pages = frame_vector_pages(buf->vec);
> + BUG_ON(IS_ERR(pages));
> if (vaddr)
> vm_unmap_ram((void *)vaddr, n_pages);
> if (buf->dma_dir == DMA_FROM_DEVICE ||
The use of BUG_ON is discouraged in the kernel. I did notice that is it
also used in the put_userptr callback in videobuf2-dma-contig.c.
I think it is much better to do something like this:
if (!buf->vec->is_pfns) {
n_pages = frame_vector_count(buf->vec);
if (vaddr)
vm_unmap_ram((void *)vaddr, n_pages);
if (buf->dma_dir == DMA_FROM_DEVICE ||
buf->dma_dir == DMA_BIDIRECTIONAL) {
pages = frame_vector_pages(buf->vec);
if (!WARN_ON_ONCE(IS_ERR(pages)))
for (i = 0; i < n_pages; i++)
set_page_dirty_lock(pages[i]);
}
} else {
and do something similar in videobuf2-dma-contig.c.
Regards,
Hans
Powered by blists - more mailing lists