media: videobuf2: Fix IS_ERR checking in vb2_vmalloc_put_userptr()
authorMa Ke <make_ruc2021@163.com>
Tue, 3 Oct 2023 09:13:15 +0000 (17:13 +0800)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Fri, 13 Oct 2023 09:33:22 +0000 (11:33 +0200)
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>
Acked-by: Tomasz Figa <tfiga@chromium.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
[hverkuil: add space between ){]
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/media/common/videobuf2/videobuf2-vmalloc.c

index 7c635e29210623a6b7f57bc87b0bcc97f8f8b6ac..7d953706f3f8002f7463273aaf5a145e17339b96 100644 (file)
@@ -133,13 +133,15 @@ 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);
                if (vaddr)
                        vm_unmap_ram((void *)vaddr, n_pages);
                if (buf->dma_dir == DMA_FROM_DEVICE ||
-                   buf->dma_dir == DMA_BIDIRECTIONAL)
-                       for (i = 0; i < n_pages; i++)
-                               set_page_dirty_lock(pages[i]);
+                   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 {
                iounmap((__force void __iomem *)buf->vaddr);
        }