patch-2.3.29 linux/drivers/isdn/pcbit/drv.c

Next file: linux/drivers/isdn/pcbit/pcbit.h
Previous file: linux/drivers/isdn/hisax/telespci.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.28/linux/drivers/isdn/pcbit/drv.c linux/drivers/isdn/pcbit/drv.c
@@ -37,6 +37,7 @@
 #include <linux/isdnif.h>
 #include <asm/string.h>
 #include <asm/io.h>
+#include <linux/ioport.h>
 
 #include "pcbit.h"
 #include "edss1.h"
@@ -88,9 +89,21 @@
 	memset(dev, 0, sizeof(struct pcbit_dev));
 	init_waitqueue_head(&dev->set_running_wq);
 
-	if (mem_base >= 0xA0000 && mem_base <= 0xFFFFF )
-		dev->sh_mem = (unsigned char*) mem_base;
-	else
+	if (mem_base >= 0xA0000 && mem_base <= 0xFFFFF ) {
+		dev->ph_mem = mem_base;
+		if (check_mem_region(dev->ph_mem, 4096)) {
+			printk(KERN_WARNING
+				"PCBIT: memory region %lx-%lx already in use\n",
+				dev->ph_mem, dev->ph_mem + 4096);
+			kfree(dev);
+			dev_pcbit[board] = NULL;
+			return -EACCES;
+		} else {
+			request_mem_region(dev->ph_mem, 4096, "PCBIT mem");
+		}
+		dev->sh_mem = (unsigned char*)ioremap(dev->ph_mem, 4096);
+	}
+	else 
 	{
 		printk("memory address invalid");
 		kfree(dev);
@@ -102,6 +115,8 @@
 	if (!dev->b1) {
 		printk("pcbit_init: couldn't malloc pcbit_chan struct\n");
 		kfree(dev);
+		iounmap((unsigned char*)dev->sh_mem);
+		release_mem_region(dev->ph_mem, 4096);
 		return -ENOMEM;
 	}
     
@@ -110,6 +125,8 @@
 		printk("pcbit_init: couldn't malloc pcbit_chan struct\n");
 		kfree(dev->b1);
 		kfree(dev);
+		iounmap((unsigned char*)dev->sh_mem);
+		release_mem_region(dev->ph_mem, 4096);
 		return -ENOMEM;
 	}
 
@@ -132,6 +149,8 @@
 		kfree(dev->b1);
 		kfree(dev->b2);
 		kfree(dev);
+		iounmap((unsigned char*)dev->sh_mem);
+		release_mem_region(dev->ph_mem, 4096);
 		dev_pcbit[board] = NULL;
 		return -EIO;
 	}
@@ -152,6 +171,8 @@
 		kfree(dev->b1);
 		kfree(dev->b2);
 		kfree(dev);
+		iounmap((unsigned char*)dev->sh_mem);
+		release_mem_region(dev->ph_mem, 4096);
 		dev_pcbit[board] = NULL;
 		return -EIO;
 	}
@@ -181,6 +202,8 @@
 		kfree(dev->b1);
 		kfree(dev->b2);
 		kfree(dev);
+		iounmap((unsigned char*)dev->sh_mem);
+		release_mem_region(dev->ph_mem, 4096);
 		dev_pcbit[board] = NULL;
 		return -EIO;
 	}
@@ -217,6 +240,8 @@
 		kfree(dev->b1);
 		kfree(dev->b2);
 		kfree(dev);
+		iounmap((unsigned char*)dev->sh_mem);
+		release_mem_region(dev->ph_mem, 4096);
 	}
 }
 #endif

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