[media] videobuf_pages_to_sg: sglist[0] length problem
authorNewson Edouard <newsondev@gmail.com>
Tue, 19 Apr 2011 14:54:54 +0000 (11:54 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Wed, 27 Jul 2011 20:52:19 +0000 (17:52 -0300)
On function videobuf_pages_to_sg the statement sg_set_page(&sglist[0],
pages[0], PAGE_SIZE - offset, offset) will fail if size is less than
PAGE_SIZE.

Signed-off-by: Newson Edouard <newsondev@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/videobuf-dma-sg.c

index ddb8f4b46c03bacea044ec9395adefdcee69350d..f300deafd268e555e54f1d9cdefbc22c97cd75cc 100644 (file)
@@ -108,8 +108,9 @@ static struct scatterlist *videobuf_pages_to_sg(struct page **pages,
        if (PageHighMem(pages[0]))
                /* DMA to highmem pages might not work */
                goto highmem;
-       sg_set_page(&sglist[0], pages[0], PAGE_SIZE - offset, offset);
-       size -= PAGE_SIZE - offset;
+       sg_set_page(&sglist[0], pages[0],
+                       min_t(size_t, PAGE_SIZE - offset, size), offset);
+       size -= min_t(size_t, PAGE_SIZE - offset, size);
        for (i = 1; i < nr_pages; i++) {
                if (NULL == pages[i])
                        goto nopage;