/* Memory for mmapped videobuf_buffers is not allocated conventionally, but by several kmalloc allocations and then creating the scatterlist on our own. User-space buffers are handled normally. Free the memory-mapped buffer memory allocated for a videobuf_buffer and the associated scatterlist.  */
static void omap24xxcam_vbq_free_mmap_buffer(struct videobuf_buffer *vb)
/* Memory for mmapped videobuf_buffers is not allocated conventionally, but by several kmalloc allocations and then creating the scatterlist on our own. User-space buffers are handled normally. Free the memory-mapped buffer memory allocated for a videobuf_buffer and the associated scatterlist.  */
static void omap24xxcam_vbq_free_mmap_buffer(struct videobuf_buffer *vb)
{
	struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
	size_t alloc_size;
	struct page *page;
	int i;
	if (dma->sglist == NULL)
		return;
	i = dma->sglen;
	while (i) {
		i--;
		alloc_size = sg_dma_len(&dma->sglist[i]);
		page = sg_page(&dma->sglist[i]);
		do {
			ClearPageReserved(page++);
		} while (alloc_size -= PAGE_SIZE);
		__free_pages(sg_page(&dma->sglist[i]),
			     get_order(sg_dma_len(&dma->sglist[i])));
	}
	kfree(dma->sglist);
	dma->sglist = NULL;
}