patch-2.4.22 linux-2.4.22/drivers/ieee1394/dma.c

Next file: linux-2.4.22/drivers/ieee1394/dma.h
Previous file: linux-2.4.22/drivers/ieee1394/csr.h
Back to the patch index
Back to the overall index

diff -urN linux-2.4.21/drivers/ieee1394/dma.c linux-2.4.22/drivers/ieee1394/dma.c
@@ -10,6 +10,7 @@
 #include <linux/module.h>
 #include <linux/vmalloc.h>
 #include <linux/slab.h>
+#include <linux/mm.h>
 #include "dma.h"
 
 /* dma_prog_region */
@@ -30,7 +31,7 @@
 	prog->n_pages = n_bytes / PAGE_SIZE;
 
 	prog->kvirt = pci_alloc_consistent(dev, prog->n_pages * PAGE_SIZE, &prog->bus_addr);
-	if(!prog->kvirt) {
+	if (!prog->kvirt) {
 		printk(KERN_ERR "dma_prog_region_alloc: pci_alloc_consistent() failed\n");
 		dma_prog_region_free(prog);
 		return -ENOMEM;
@@ -43,7 +44,7 @@
 
 void dma_prog_region_free(struct dma_prog_region *prog)
 {
-	if(prog->kvirt) {
+	if (prog->kvirt) {
 		pci_free_consistent(prog->dev, prog->n_pages * PAGE_SIZE, prog->kvirt, prog->bus_addr);
 	}
 
@@ -74,7 +75,7 @@
 	n_pages = n_bytes / PAGE_SIZE;
 
 	dma->kvirt = vmalloc_32(n_pages * PAGE_SIZE);
-	if(!dma->kvirt) {
+	if (!dma->kvirt) {
 		printk(KERN_ERR "dma_region_alloc: vmalloc_32() failed\n");
 		goto err;
 	}
@@ -86,7 +87,7 @@
 
 	/* allocate scatter/gather list */
 	dma->sglist = kmalloc(dma->n_pages * sizeof(struct scatterlist), GFP_KERNEL);
-	if(!dma->sglist) {
+	if (!dma->sglist) {
 		printk(KERN_ERR "dma_region_alloc: kmalloc(sglist) failed\n");
 		goto err;
 	}
@@ -95,7 +96,7 @@
 	memset(dma->sglist, 0, dma->n_pages * sizeof(struct scatterlist));
 
 	/* fill scatter/gather list with pages */
-	for(i = 0; i < dma->n_pages; i++) {
+	for (i = 0; i < dma->n_pages; i++) {
 		unsigned long va = (unsigned long) dma->kvirt + i * PAGE_SIZE;
 			
 		dma->sglist[i].page = vmalloc_to_page((void *)va);
@@ -105,7 +106,7 @@
 	/* map sglist to the IOMMU */
 	dma->n_dma_pages = pci_map_sg(dev, &dma->sglist[0], dma->n_pages, direction);
 
-	if(dma->n_dma_pages == 0) {
+	if (dma->n_dma_pages == 0) {
 		printk(KERN_ERR "dma_region_alloc: pci_map_sg() failed\n");
 		goto err;
 	}
@@ -122,18 +123,18 @@
 
 void dma_region_free(struct dma_region *dma)
 {
-	if(dma->n_dma_pages) {
+	if (dma->n_dma_pages) {
 		pci_unmap_sg(dma->dev, dma->sglist, dma->n_pages, dma->direction);
 		dma->n_dma_pages = 0;
 		dma->dev = NULL;
 	}
 
-	if(dma->sglist) {
+	if (dma->sglist) {
 		kfree(dma->sglist);
 		dma->sglist = NULL;
 	}
 
-	if(dma->kvirt) {
+	if (dma->kvirt) {
 		vfree(dma->kvirt);
 		dma->kvirt = NULL;
 		dma->n_pages = 0;
@@ -147,16 +148,18 @@
 	int i;
 	unsigned long off = offset;
 
-	for(i = 0; i < dma->n_dma_pages; i++) {
-		if(off < sg_dma_len(&dma->sglist[i])) {
+	for (i = 0; i < dma->n_dma_pages; i++) {
+		if (off < sg_dma_len(&dma->sglist[i])) {
 			*rem = off;
-			return i;
+			break;
 		}
 
 		off -= sg_dma_len(&dma->sglist[i]);
 	}
 
-	panic("dma_region_find: offset %lu beyond end of DMA mapping\n", offset);
+	BUG_ON(i >= dma->n_dma_pages);
+
+	return i;
 }
 
 dma_addr_t dma_region_offset_to_bus(struct dma_region *dma, unsigned long offset)
@@ -172,7 +175,7 @@
 	int first, last;
 	unsigned long rem;
 
-	if(!len)
+	if (!len)
 		len = 1;
 
 	first = dma_region_find(dma, offset, &rem);
@@ -192,10 +195,10 @@
 
 	struct dma_region *dma = (struct dma_region*) area->vm_private_data;
 
-	if(!dma->kvirt)
+	if (!dma->kvirt)
 		goto out;
 
-	if( (address < (unsigned long) area->vm_start) ||
+	if ( (address < (unsigned long) area->vm_start) ||
 	    (address > (unsigned long) area->vm_start + (PAGE_SIZE * dma->n_pages)) )
 		goto out;
 
@@ -215,16 +218,16 @@
 {
 	unsigned long size;
 
-	if(!dma->kvirt)
+	if (!dma->kvirt)
 		return -EINVAL;
 
 	/* must be page-aligned */
-	if(vma->vm_pgoff != 0)
+	if (vma->vm_pgoff != 0)
 		return -EINVAL;
 
 	/* check the length */
 	size = vma->vm_end - vma->vm_start;
-	if(size > (PAGE_SIZE * dma->n_pages))
+	if (size > (PAGE_SIZE * dma->n_pages))
 		return -EINVAL;
 
 	vma->vm_ops = &dma_region_vm_ops;

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)