Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / char / applicom.c
index 148ea29..a370e7a 100644 (file)
@@ -1,6 +1,6 @@
 /* Derived from Applicom driver ac.c for SCO Unix                            */
 /* Ported by David Woodhouse, Axiom (Cambridge) Ltd.                         */
-/* dwmw2@redhat.com  30/8/98                                                 */
+/* dwmw2@infradead.org 30/8/98                                               */
 /* $Id: ac.c,v 1.30 2000/03/22 16:03:57 dwmw2 Exp $                         */
 /* This module is for Linux 2.1 and 2.2 series kernels.                      */
 /*****************************************************************************/
@@ -79,10 +79,6 @@ MODULE_DEVICE_TABLE(pci, applicom_pci_tbl);
 MODULE_AUTHOR("David Woodhouse & Applicom International");
 MODULE_DESCRIPTION("Driver for Applicom Profibus card");
 MODULE_LICENSE("GPL");
-MODULE_PARM(irq, "i");
-MODULE_PARM_DESC(irq, "IRQ of the Applicom board");
-MODULE_PARM(mem, "i");
-MODULE_PARM_DESC(mem, "Shared Memory Address of Applicom board");
 
 MODULE_SUPPORTED_DEVICE("ac");
 
@@ -98,6 +94,11 @@ static struct applicom_board {
 static unsigned int irq = 0;   /* interrupt number IRQ       */
 static unsigned long mem = 0;  /* physical segment of board  */
 
+module_param(irq, uint, 0);
+MODULE_PARM_DESC(irq, "IRQ of the Applicom board");
+module_param(mem, ulong, 0);
+MODULE_PARM_DESC(mem, "Shared Memory Address of Applicom board");
+
 static unsigned int numboards; /* number of installed boards */
 static volatile unsigned char Dummy;
 static DECLARE_WAIT_QUEUE_HEAD(FlagSleepRec);
@@ -141,7 +142,7 @@ static int ac_register_board(unsigned long physloc, void __iomem *loc,
        if (!boardno)
                boardno = readb(loc + NUMCARD_OWNER_TO_PC);
 
-       if (!boardno && boardno > MAX_BOARD) {
+       if (!boardno || boardno > MAX_BOARD) {
                printk(KERN_WARNING "Board #%d (at 0x%lx) is out of range (1 <= x <= %d).\n",
                       boardno, physloc, MAX_BOARD);
                return 0;
@@ -171,7 +172,7 @@ static int ac_register_board(unsigned long physloc, void __iomem *loc,
 
 void cleanup_module(void)
 {
-       int i;
+       unsigned int i;
 
        misc_deregister(&ac_miscdev);
 
@@ -194,13 +195,13 @@ int __init applicom_init(void)
        int i, numisa = 0;
        struct pci_dev *dev = NULL;
        void __iomem *RamIO;
-       int boardno;
+       int boardno, ret;
 
        printk(KERN_INFO "Applicom driver: $Id: ac.c,v 1.30 2000/03/22 16:03:57 dwmw2 Exp $\n");
 
        /* No mem and irq given - check for a PCI card */
 
-       while ( (dev = pci_find_class(PCI_CLASS_OTHERS << 16, dev))) {
+       while ( (dev = pci_get_class(PCI_CLASS_OTHERS << 16, dev))) {
 
                if (dev->vendor != PCI_VENDOR_ID_APPLICOM)
                        continue;
@@ -293,7 +294,8 @@ int __init applicom_init(void)
        }
 
        if (!numisa)
-               printk(KERN_WARNING"ac.o: No valid ISA Applicom boards found at mem 0x%lx\n",mem);
+               printk(KERN_WARNING "ac.o: No valid ISA Applicom boards found "
+                               "at mem 0x%lx\n", mem);
 
  fin:
        init_waitqueue_head(&FlagSleepRec);
@@ -303,7 +305,11 @@ int __init applicom_init(void)
        DeviceErrorCount = 0;
 
        if (numboards) {
-               misc_register(&ac_miscdev);
+               ret = misc_register(&ac_miscdev);
+               if (ret) {
+                       printk(KERN_WARNING "ac.o: Unable to register misc device\n");
+                       goto out;
+               }
                for (i = 0; i < MAX_BOARD; i++) {
                        int serial;
                        char boardname[(SERIAL_NUMBER - TYPE_CARD) + 1];
@@ -336,6 +342,17 @@ int __init applicom_init(void)
 
        else
                return -ENXIO;
+
+out:
+       for (i = 0; i < MAX_BOARD; i++) {
+               if (!apbs[i].RamIO)
+                       continue;
+               if (apbs[i].irq)
+                       free_irq(apbs[i].irq, &dummy);
+               iounmap(apbs[i].RamIO);
+       }
+       pci_disable_device(dev);
+       return ret;
 }
 
 
@@ -598,7 +615,7 @@ static ssize_t ac_read (struct file *filp, char __user *buf, size_t count, loff_
 
 #ifdef DEBUG
                if (loopcount++ > 2) {
-                       printk("Looping in ac_read. loopcount %d\n", loopcount);
+                       printk(KERN_DEBUG "Looping in ac_read. loopcount %d\n", loopcount);
                }
 #endif
        }