diff mbox

videobuf_pages_to_sg: sglist[0] length problem

Message ID BANLkTikupnA4_muR6zTuhX6VfsidnJ0Q3g@mail.gmail.com (mailing list archive)
State Accepted
Headers show

Commit Message

Newson Edouard April 19, 2011, 2:54 p.m. UTC
On function videobuf_pages_to_sg the statement sg_set_page(&sglist[0],
pages[0], PAGE_SIZE -
offset, offset) will failed if if size is less than PAGE_SIZE.

Signed-off-by: Newson Edouard <newsondev@gmail.com

---
 drivers/media/video/videobuf-dma-sg.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

 			goto nopage;
diff mbox

Patch

diff --git a/drivers/media/video/videobuf-dma-sg.c
b/drivers/media/video/videobuf-dma-sg.c
index ddb8f4b..f300dea 100644
--- a/drivers/media/video/videobuf-dma-sg.c
+++ b/drivers/media/video/videobuf-dma-sg.c
@@ -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])