I'm in the process of trying to figure out why my usb-ohci controller is
not working properly, and have found a couple of buglets in the
initialization of the device.

For the most part, they are just "little" things, such as not releasing
resources and such upon failure.  Please accept my patch if there aren't
any issues with it.

--- linux-2.4.17stock/drivers/usb/usb-ohci.c    Fri Dec 21 11:41:55 2001
+++ linux/drivers/usb/usb-ohci.c        Tue Jan 22 10:45:19 2002
@@ -12,6 +12,8 @@
  *
  * History:
  *
+ * 2002/01/18 Fixes to make driver cleanup after itself if it doesn't
+ *     load properly
  * 2001/09/19 USB_ZERO_PACKET support (Jean Tourrilhes)
  * 2001/07/17 power management and pmac cleanup (Benjamin Herrenschmidt)
  * 2001/03/24 td/ed hashing to remove bus_to_virt (Steve Longerbeam);
@@ -47,6 +49,7 @@
  * v1.0 1999/04/27 initial release
  */

+
 #include <linux/config.h>
 #include <linux/module.h>
 #include <linux/pci.h>
@@ -2382,6 +2385,8 @@
        bus = usb_alloc_bus (&sohci_device_operations);
        if (!bus) {
                kfree (ohci);
+               pci_set_drvdata(dev, NULL);
+               pci_free_consistent(ohci->ohci_dev, sizeof *ohci->hcca, ohci->hcca, 
+ohci->hcca_dma);
                return NULL;
        }

@@ -2413,8 +2418,11 @@
        }
        pci_set_drvdata(ohci->ohci_dev, NULL);

-       usb_deregister_bus (ohci->bus);
-       usb_free_bus (ohci->bus);
+       if (ohci->bus) {
+               if (ohci->bus->busnum)
+                       usb_deregister_bus (ohci->bus);
+               usb_free_bus (ohci->bus);
+       }

        list_del (&ohci->ohci_hcd_list);
        INIT_LIST_HEAD (&ohci->ohci_hcd_list);
@@ -2560,6 +2568,7 @@
 static int __devinit
 ohci_pci_probe (struct pci_dev *dev, const struct pci_device_id *id)
 {
+       int res = 0;
        unsigned long mem_resource, mem_len;
        void *mem_base;

@@ -2568,6 +2577,7 @@

         if (!dev->irq) {
                err("found OHCI device with no IRQ assigned. check BIOS
settings!");
+               pci_disable_device(dev);
                return -ENODEV;
         }

@@ -2576,19 +2586,31 @@
        mem_len = pci_resource_len(dev, 0);
        if (!request_mem_region (mem_resource, mem_len,
ohci_pci_driver.name)) {
                dbg ("controller already in use");
+               pci_disable_device(dev);
                return -EBUSY;
        }

        mem_base = ioremap_nocache (mem_resource, mem_len);
        if (!mem_base) {
                err("Error mapping OHCI memory");
+               release_mem_region(mem_resource, mem_len);
+               pci_disable_device(dev);
                return -EFAULT;
        }

        /* controller writes into our memory */
        pci_set_master (dev);

-       return hc_found_ohci (dev, dev->irq, mem_base, id);
+       res = hc_found_ohci (dev, dev->irq, mem_base, id);
+       if (res < 0) {
+               iounmap(mem_base);
+               release_mem_region(mem_resource, mem_len);
+               pci_disable_device(dev);
+       }
+
+       return res;
+
+
 }


/*-------------------------------------------------------------------------*/
@@ -2890,3 +2912,4 @@
 MODULE_AUTHOR( DRIVER_AUTHOR );
 MODULE_DESCRIPTION( DRIVER_DESC );
 MODULE_LICENSE("GPL");
+


Thanks,
Matthew Fredrickson


_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to