Staging: comedi: Fixed long line lengths in drivers.c
PATCH 1/1 Staging: comedi: Fixed long line lengths in drivers.c
This patch clears up some long line length warnings in drivers.c found by checkpatch
--- drivers/staging/comedi/drivers.c | 31 ++++++++++++++++++++++--------- 1 files changed, 22 insertions(+), 9 deletions(-)
drivers/staging/comedi/drivers.c +22 -9
@@ -117,8 +117,9 @@ int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it)for (driv = comedi_drivers; driv; driv = driv->next) {if (!try_module_get (driv->module)) { -printk - (KERN_INFO "comedi: failed to increment module count, skipping\n" ); +printk (KERN_INFO +"comedi: " +"failed to increment module count, skipping\n" );continue ; }if (driv->num_names) {
@@ -205,9 +206,10 @@ int comedi_driver_unregister(struct comedi_driver *driver)mutex_lock (&dev->mutex);if (dev->attached && dev->driver == driver) {if (dev->use_count) -printk - (KERN_WARNING "BUG! detaching device with use_count=%d\n" , - dev->use_count); +printk (KERN_WARNING +"BUG! detaching device with use_count=" +"%d\n" , + dev->use_count);comedi_device_detach (dev); }mutex_unlock (&dev->mutex);
@@ -442,7 +444,10 @@ int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,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)); +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,
@@ -496,8 +501,12 @@ int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,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); + &(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) {
@@ -514,7 +523,11 @@ int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s, NULL) {break ; } -clear_bit (PG_reserved, &(virt_to_page (async->buf_page_list[i].virt_addr)->flags)); +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,
Signature · 1 line
1.7.0.5
Quoted 4 lines · Mark
This patch clears up some long line length warnings in
drivers.cfound by checkpatchSigned-off-by Mark Rankilor <[email protected]>
Hi Mark.
drivers/staging/comedi/drivers.c int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s, · line 445
Quoted 9 lines
drivers/staging/comedi/drivers.c +0
-1@@ -442,7 +444,10 @@ int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,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));
It's better to not just fix the checkpatch errors by simply wrapping the code, but rather to factor the code for clarity.
Using a temporary would fix a lot of these long line problems.
Moving these into static alloc/free functions would help as well.
Perhaps something like:
--- drivers/staging/comedi/drivers.c | 188 ++++++++++++++++++-------------------- 1 files changed, 87 insertions(+), 101 deletions(-)
drivers/staging/comedi/drivers.c +87 -101
@@ -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
Quoted 4 lines · Joe Perches
It's better to not just fix the checkpatch errors by simply wrapping the code, but rather to factor the code for clarity.
Perhaps something like:
Joe, thanks for the help and code, it looks good so far to me, though I haven't had time to look through thoroughly enough tonight.
I'll give it a longer look in my next hacking session :)
Cheers,
Mark