Linus,

Here's a patch that fixes a bug that can cause PCI driver list
corruption.  If parport_pc's init_module fails after it calls
pci_register_driver, cleanup_module isn't called and so it's still
registered when it gets unloaded.

Tim.
*/

2001-01-13  Tim Waugh  <[EMAIL PROTECTED]>

        * parport_pc.c: Fix PCI driver list corruption on
        unsuccessful module load (Andrew Morton).

--- linux/drivers/parport/parport_pc.c.init     Tue Feb 13 23:31:25 2001
+++ linux/drivers/parport/parport_pc.c  Tue Feb 13 23:35:56 2001
@@ -89,6 +89,7 @@
 } superios[NR_SUPERIOS] __devinitdata = { {0,},};
 
 static int user_specified __devinitdata = 0;
+static int registered_parport;
 
 /* frob_control, but for ECR */
 static void frob_econtrol (struct parport *pb, unsigned char m,
@@ -2605,6 +2606,7 @@
        count += parport_pc_find_nonpci_ports (autoirq, autodma);
 
        r = pci_register_driver (&parport_pc_pci_driver);
+       registered_parport = 1;
        if (r > 0)
                count += r;
 
@@ -2667,6 +2669,7 @@
        /* Work out how many ports we have, then get parport_share to parse
           the irq values. */
        unsigned int i;
+       int ret;
        for (i = 0; i < PARPORT_PC_MAX_PORTS && io[i]; i++);
        if (i) {
                if (parport_parse_irqs(i, irq, irqval)) return 1;
@@ -2691,7 +2694,11 @@
                        }
        }
 
-       return !parport_pc_init (io, io_hi, irqval, dmaval);
+       ret = !parport_pc_init (io, io_hi, irqval, dmaval);
+       if (ret && registered_parport)
+               pci_unregister_driver (&parport_pc_pci_driver);
+
+       return ret;
 }
 
 void cleanup_module(void)
*** linux/drivers/parport/ChangeLog.init        Fri Jan  5 10:41:52 2001
--- linux/drivers/parport/ChangeLog     Tue Feb 13 23:32:02 2001
***************
*** 0 ****
--- 1,7 ----
+ 2001-02-13  Andrew Morton <[EMAIL PROTECTED]>
+ 
+       * parport_pc.c (registered_parport): New static variable.
+       (parport_pc_find_ports): Set it when we register PCI driver.
+       (init_module): Unregister PCI driver if necessary when we
+       fail.
+ 
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to