diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2010-06-02 14:18:29 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2010-06-02 14:18:29 +0200 |
commit | 5444ca9d5fb255ea35fc60bf1cb27d29135cfbf3 (patch) | |
tree | aa15b5f85a66ef0997b7fd341dbc6cbb637b67e8 | |
parent | 454203ed354c84c6947bb774c8deda9b2646e190 (diff) |
Align userspace buffers to a page size boundary
Some devices need userspace buffers to be page-aligned. Use the
posix_memalign function instead of malloc to allocate page-aligned
buffers.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-rw-r--r-- | yavta.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -270,6 +270,7 @@ static int video_alloc_buffers(struct device *dev, int nbufs) { struct v4l2_requestbuffers rb; struct v4l2_buffer buf; + int page_size; void **bufmem; unsigned int i; int ret; @@ -291,6 +292,8 @@ static int video_alloc_buffers(struct device *dev, int nbufs) if (bufmem == NULL) return -ENOMEM; + page_size = getpagesize(); + /* Map the buffers. */ for (i = 0; i < rb.count; ++i) { memset(&buf, 0, sizeof buf); @@ -315,9 +318,9 @@ static int video_alloc_buffers(struct device *dev, int nbufs) break; case V4L2_MEMORY_USERPTR: - bufmem[i] = malloc(buf.length); - if (bufmem[i] == NULL) { - printf("Unable to allocate buffer %u (%d)\n", i, errno); + ret = posix_memalign(&bufmem[i], page_size, buf.length); + if (ret < 0) { + printf("Unable to allocate buffer %u (%d)\n", i, ret); return -ENOMEM; } printf("Buffer %u allocated at address %p.\n", i, bufmem[i]); |