Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 354021
b: refs/heads/master
c: 718c4d6
h: refs/heads/master
i:
  354019: fdc3e38
v: v3
  • Loading branch information
H Hartley Sweeten authored and Greg Kroah-Hartman committed Jan 18, 2013
1 parent fce2c0f commit bc6aac6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 64 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: ea082fb1b0ee42b6430c83a6dc9d795381a87264
refs/heads/master: 718c4d68d9491e8bc16a614d193b257efc41723e
106 changes: 43 additions & 63 deletions trunk/drivers/staging/comedi/comedi_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,43 @@
#include "comedidev.h"
#include "comedi_internal.h"

static void __comedi_buf_free(struct comedi_device *dev,
struct comedi_subdevice *s,
unsigned n_pages)
{
struct comedi_async *async = s->async;
struct comedi_buf_page *buf;
unsigned i;

if (async->prealloc_buf) {
vunmap(async->prealloc_buf);
async->prealloc_buf = NULL;
async->prealloc_bufsz = 0;
}

if (!async->buf_page_list)
return;

for (i = 0; i < n_pages; ++i) {
buf = &async->buf_page_list[i];
if (buf->virt_addr) {
clear_bit(PG_reserved,
&(virt_to_page(buf->virt_addr)->flags));
if (s->async_dma_dir != DMA_NONE) {
dma_free_coherent(dev->hw_dev,
PAGE_SIZE,
buf->virt_addr,
buf->dma_addr);
} else {
free_page((unsigned long)buf->virt_addr);
}
}
}
vfree(async->buf_page_list);
async->buf_page_list = NULL;
async->n_buf_pages = 0;
}

int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,
unsigned long new_size)
{
Expand All @@ -34,39 +71,9 @@ int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,
if (async->prealloc_buf && async->prealloc_bufsz == new_size)
return 0;

/* deallocate old buffer */
if (async->prealloc_buf) {
vunmap(async->prealloc_buf);
async->prealloc_buf = NULL;
async->prealloc_bufsz = 0;
}
if (async->buf_page_list) {
unsigned i;
for (i = 0; i < async->n_buf_pages; ++i) {
if (async->buf_page_list[i].virt_addr) {
clear_bit(PG_reserved,
&(virt_to_page(async->buf_page_list[i].
virt_addr)->flags));
if (s->async_dma_dir != DMA_NONE) {
dma_free_coherent(dev->hw_dev,
PAGE_SIZE,
async->
buf_page_list
[i].virt_addr,
async->
buf_page_list
[i].dma_addr);
} else {
free_page((unsigned long)
async->buf_page_list[i].
virt_addr);
}
}
}
vfree(async->buf_page_list);
async->buf_page_list = NULL;
async->n_buf_pages = 0;
}
/* deallocate old buffer */
__comedi_buf_free(dev, s, async->n_buf_pages);

/* allocate new buffer */
if (new_size) {
unsigned i = 0;
Expand Down Expand Up @@ -114,36 +121,9 @@ int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,
}
vfree(pages);

if (async->prealloc_buf == NULL) {
/* Some allocation failed above. */
if (async->buf_page_list) {
for (i = 0; i < n_pages; i++) {
if (async->buf_page_list[i].virt_addr ==
NULL) {
break;
}
clear_bit(PG_reserved,
&(virt_to_page(async->
buf_page_list[i].
virt_addr)->flags));
if (s->async_dma_dir != DMA_NONE) {
dma_free_coherent(dev->hw_dev,
PAGE_SIZE,
async->
buf_page_list
[i].virt_addr,
async->
buf_page_list
[i].dma_addr);
} else {
free_page((unsigned long)
async->buf_page_list
[i].virt_addr);
}
}
vfree(async->buf_page_list);
async->buf_page_list = NULL;
}
if (!async->prealloc_buf) {
/* Some allocation failed above */
__comedi_buf_free(dev, s, n_pages);
return -ENOMEM;
}
async->n_buf_pages = n_pages;
Expand Down

0 comments on commit bc6aac6

Please sign in to comment.