* [PATCH] Staging: comedi: Refactored code to fix long line lengths in drivers.c
@ 2010-05-24 9:22 Mark
2010-05-24 17:16 ` Joe Perches
0 siblings, 1 reply; 3+ messages in thread
From: Mark @ 2010-05-24 9:22 UTC (permalink / raw)
To: joe, gregkh; +Cc: Mark, Mithlesh Thukral, Bill Pemberton, devel, linux-kernel
Joe I'm happy with this patch, so we can submit it as is. I've added a
signed-off-by line for you below since it is really your code, is that ok for me
to add that?
This patch refactors some code to clean up some long line length checkpatch
warnings.
Signed-off-by: Mark Rankilor <reodge@gmail.com>
Signed-off-by: Joe Perches <joe@perches.com>
---
drivers/staging/comedi/drivers.c | 188 ++++++++++++++++++--------------------
1 files changed, 87 insertions(+), 101 deletions(-)
diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index 4a29ed7..bdbbe8e 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -420,6 +420,91 @@ static inline unsigned long kvirt_to_kva(unsigned long adr)
return kva;
}
+static void free_buf_page_list(struct comedi_device *dev,
+ struct comedi_subdevice *s)
+{
+ int i;
+ struct comedi_async *async = s->async;
+ struct comedi_buf_page *bp = async->buf_page_list;
+
+ if (!async->buf_page_list)
+ return;
+
+ for (i = 0; i < async->n_buf_pages; ++i) {
+ if (bp->virt_addr) {
+ clear_bit(PG_reserved,
+ &virt_to_page(bp->virt_addr)->flags);
+ if (s->async_dma_dir != DMA_NONE) {
+ dma_free_coherent(dev->hw_dev, PAGE_SIZE,
+ bp->virt_addr, bp->dma_addr);
+ } else {
+ free_page((unsigned long)bp->virt_addr);
+ }
+ }
+ bp++;
+ }
+ vfree(async->buf_page_list);
+ async->buf_page_list = NULL;
+ async->n_buf_pages = 0;
+}
+
+static int alloc_buf_page_list(struct comedi_device *dev,
+ struct comedi_subdevice *s,
+ unsigned long new_size)
+{
+ unsigned i = 0;
+ struct comedi_async *async = s->async;
+ unsigned n_pages = new_size >> PAGE_SHIFT;
+ unsigned bp_size = sizeof(struct comedi_buf_page) * n_pages;
+ struct page **pages = NULL;
+
+ /* allocate new buffer */
+ if (!new_size)
+ return 0;
+
+ async->buf_page_list = vmalloc(bp_size);
+ if (!async->buf_page_list)
+ return -ENOMEM;
+ memset(async->buf_page_list, 0, bp_size);
+ pages = vmalloc(sizeof(struct page *) * n_pages);
+ if (pages) {
+ struct comedi_buf_page *bp = async->buf_page_list;
+ for (i = 0; i < n_pages; i++) {
+ if (s->async_dma_dir != DMA_NONE) {
+ bp->virt_addr =
+ dma_alloc_coherent(dev->hw_dev,
+ PAGE_SIZE,
+ &bp->dma_addr,
+ GFP_KERNEL |
+ __GFP_COMP);
+ } else {
+ bp->virt_addr = (void *)
+ get_zeroed_page(GFP_KERNEL);
+ }
+ if (bp->virt_addr == NULL) {
+ vfree(pages);
+ free_buf_page_list(dev, s);
+ return -ENOMEM;
+ }
+
+ set_bit(PG_reserved,
+ &virt_to_page(bp->virt_addr)->flags);
+ pages[i] = virt_to_page(bp->virt_addr);
+ bp++;
+ }
+ }
+
+ async->prealloc_buf = vmap(pages, n_pages, VM_MAP, PAGE_KERNEL_NOCACHE);
+ vfree(pages);
+ if (!async->prealloc_buf) {
+ free_buf_page_list(dev, s);
+ return -ENOMEM;
+ }
+ async->n_buf_pages = n_pages;
+ async->prealloc_bufsz = new_size;
+ return 0;
+}
+
int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,
unsigned long new_size)
{
@@ -438,108 +523,9 @@ int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,
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;
- }
- /* allocate new buffer */
- if (new_size) {
- unsigned i = 0;
- unsigned n_pages = new_size >> PAGE_SHIFT;
- struct page **pages = NULL;
-
- async->buf_page_list =
- vmalloc(sizeof(struct comedi_buf_page) * n_pages);
- if (async->buf_page_list) {
- memset(async->buf_page_list, 0,
- sizeof(struct comedi_buf_page) * n_pages);
- pages = vmalloc(sizeof(struct page *) * n_pages);
- }
- if (pages) {
- for (i = 0; i < n_pages; i++) {
- if (s->async_dma_dir != DMA_NONE) {
- async->buf_page_list[i].virt_addr =
- dma_alloc_coherent(dev->hw_dev,
- PAGE_SIZE,
- &async->
- buf_page_list
- [i].dma_addr,
- GFP_KERNEL |
- __GFP_COMP);
- } else {
- async->buf_page_list[i].virt_addr =
- (void *)
- get_zeroed_page(GFP_KERNEL);
- }
- if (async->buf_page_list[i].virt_addr == NULL)
- break;
-
- set_bit(PG_reserved,
- &(virt_to_page(async->buf_page_list[i].virt_addr)->flags));
- pages[i] = virt_to_page(async->buf_page_list[i].virt_addr);
- }
- }
- if (i == n_pages) {
- async->prealloc_buf =
- vmap(pages, n_pages, VM_MAP, PAGE_KERNEL_NOCACHE);
- }
- 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;
- }
- return -ENOMEM;
- }
- async->n_buf_pages = n_pages;
- }
- async->prealloc_bufsz = new_size;
- return 0;
+ free_buf_page_list(dev, s);
+ return alloc_buf_page_list(dev, s, new_size);
}
/* munging is applied to data by core as it passes between user
--
1.7.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Staging: comedi: Refactored code to fix long line lengths in drivers.c
2010-05-24 9:22 [PATCH] Staging: comedi: Refactored code to fix long line lengths in drivers.c Mark
@ 2010-05-24 17:16 ` Joe Perches
0 siblings, 0 replies; 3+ messages in thread
From: Joe Perches @ 2010-05-24 17:16 UTC (permalink / raw)
To: Mark; +Cc: gregkh, Mithlesh Thukral, Bill Pemberton, devel, linux-kernel
On Mon, 2010-05-24 at 17:22 +0800, Mark wrote:
> Joe I'm happy with this patch, so we can submit it as is. I've added a
> signed-off-by line for you below since it is really your code, is that ok for me
> to add that?
I was just typing for example's sake.
I didn't compile it or test it.
If you have, fine.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] Staging: comedi: Refactored code to fix long line lengths in drivers.c
2010-05-31 9:19 [PATCH] Staging: comedi: Checkpatch cleanups in adl_pci9111.c Mark
@ 2010-05-31 9:19 ` Mark
0 siblings, 0 replies; 3+ messages in thread
From: Mark @ 2010-05-31 9:19 UTC (permalink / raw)
To: gregkh
Cc: Mark, Joe Perches, Mithlesh Thukral, Bill Pemberton, devel,
linux-kernel
This patch refactors some code to clean up some long line length checkpatch
warnings.
Signed-off-by: Mark Rankilor <reodge@gmail.com>
Signed-off-by: Joe Perches <joe@perches.com>
---
drivers/staging/comedi/drivers.c | 188 ++++++++++++++++++--------------------
1 files changed, 87 insertions(+), 101 deletions(-)
diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index 4a29ed7..bdbbe8e 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -420,6 +420,91 @@ static inline unsigned long kvirt_to_kva(unsigned long adr)
return kva;
}
+static void free_buf_page_list(struct comedi_device *dev,
+ struct comedi_subdevice *s)
+{
+ int i;
+ struct comedi_async *async = s->async;
+ struct comedi_buf_page *bp = async->buf_page_list;
+
+ if (!async->buf_page_list)
+ return;
+
+ for (i = 0; i < async->n_buf_pages; ++i) {
+ if (bp->virt_addr) {
+ clear_bit(PG_reserved,
+ &virt_to_page(bp->virt_addr)->flags);
+ if (s->async_dma_dir != DMA_NONE) {
+ dma_free_coherent(dev->hw_dev, PAGE_SIZE,
+ bp->virt_addr, bp->dma_addr);
+ } else {
+ free_page((unsigned long)bp->virt_addr);
+ }
+ }
+ bp++;
+ }
+ vfree(async->buf_page_list);
+ async->buf_page_list = NULL;
+ async->n_buf_pages = 0;
+}
+
+static int alloc_buf_page_list(struct comedi_device *dev,
+ struct comedi_subdevice *s,
+ unsigned long new_size)
+{
+ unsigned i = 0;
+ struct comedi_async *async = s->async;
+ unsigned n_pages = new_size >> PAGE_SHIFT;
+ unsigned bp_size = sizeof(struct comedi_buf_page) * n_pages;
+ struct page **pages = NULL;
+
+ /* allocate new buffer */
+ if (!new_size)
+ return 0;
+
+ async->buf_page_list = vmalloc(bp_size);
+ if (!async->buf_page_list)
+ return -ENOMEM;
+ memset(async->buf_page_list, 0, bp_size);
+ pages = vmalloc(sizeof(struct page *) * n_pages);
+ if (pages) {
+ struct comedi_buf_page *bp = async->buf_page_list;
+ for (i = 0; i < n_pages; i++) {
+ if (s->async_dma_dir != DMA_NONE) {
+ bp->virt_addr =
+ dma_alloc_coherent(dev->hw_dev,
+ PAGE_SIZE,
+ &bp->dma_addr,
+ GFP_KERNEL |
+ __GFP_COMP);
+ } else {
+ bp->virt_addr = (void *)
+ get_zeroed_page(GFP_KERNEL);
+ }
+ if (bp->virt_addr == NULL) {
+ vfree(pages);
+ free_buf_page_list(dev, s);
+ return -ENOMEM;
+ }
+
+ set_bit(PG_reserved,
+ &virt_to_page(bp->virt_addr)->flags);
+ pages[i] = virt_to_page(bp->virt_addr);
+ bp++;
+ }
+ }
+
+ async->prealloc_buf = vmap(pages, n_pages, VM_MAP, PAGE_KERNEL_NOCACHE);
+ vfree(pages);
+ if (!async->prealloc_buf) {
+ free_buf_page_list(dev, s);
+ return -ENOMEM;
+ }
+ async->n_buf_pages = n_pages;
+ async->prealloc_bufsz = new_size;
+ return 0;
+}
+
int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,
unsigned long new_size)
{
@@ -438,108 +523,9 @@ int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,
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;
- }
- /* allocate new buffer */
- if (new_size) {
- unsigned i = 0;
- unsigned n_pages = new_size >> PAGE_SHIFT;
- struct page **pages = NULL;
-
- async->buf_page_list =
- vmalloc(sizeof(struct comedi_buf_page) * n_pages);
- if (async->buf_page_list) {
- memset(async->buf_page_list, 0,
- sizeof(struct comedi_buf_page) * n_pages);
- pages = vmalloc(sizeof(struct page *) * n_pages);
- }
- if (pages) {
- for (i = 0; i < n_pages; i++) {
- if (s->async_dma_dir != DMA_NONE) {
- async->buf_page_list[i].virt_addr =
- dma_alloc_coherent(dev->hw_dev,
- PAGE_SIZE,
- &async->
- buf_page_list
- [i].dma_addr,
- GFP_KERNEL |
- __GFP_COMP);
- } else {
- async->buf_page_list[i].virt_addr =
- (void *)
- get_zeroed_page(GFP_KERNEL);
- }
- if (async->buf_page_list[i].virt_addr == NULL)
- break;
-
- set_bit(PG_reserved,
- &(virt_to_page(async->buf_page_list[i].virt_addr)->flags));
- pages[i] = virt_to_page(async->buf_page_list[i].virt_addr);
- }
- }
- if (i == n_pages) {
- async->prealloc_buf =
- vmap(pages, n_pages, VM_MAP, PAGE_KERNEL_NOCACHE);
- }
- 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;
- }
- return -ENOMEM;
- }
- async->n_buf_pages = n_pages;
- }
- async->prealloc_bufsz = new_size;
- return 0;
+ free_buf_page_list(dev, s);
+ return alloc_buf_page_list(dev, s, new_size);
}
/* munging is applied to data by core as it passes between user
--
1.7.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-05-31 9:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-24 9:22 [PATCH] Staging: comedi: Refactored code to fix long line lengths in drivers.c Mark
2010-05-24 17:16 ` Joe Perches
-- strict thread matches above, loose matches on Subject: below --
2010-05-31 9:19 [PATCH] Staging: comedi: Checkpatch cleanups in adl_pci9111.c Mark
2010-05-31 9:19 ` [PATCH] Staging: comedi: Refactored code to fix long line lengths in drivers.c Mark
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).