When controller initialisation is aborted in grub_uhci_pci_iter
(grub_ohci_pci_iter) control
jumps to "fail:", where any allocated memory is freed. However, the
struct grub_uhci *u
(struct grub_ohci *o) for that controller remains linked to the list
of UHCI (OHCI)
controllers. This causes problems later, when grub iterates over
controllers to initialise
their ports.

The solution is to link only when the usb controller is successfully
initialised, and just
before returning from the function.

This patch is tested with real hardware and with qemu and the rescue image.


Thanks,
Oliver
ChangeLog:

        * bus/usb/ohci.c: Link struct only after initialising controller.
        * bus/usb/uhci.c: Likewise.

Index: bus/usb/ohci.c
===================================================================
--- bus/usb/ohci.c	(revision 2216)
+++ bus/usb/ohci.c	(working copy)
@@ -153,9 +153,6 @@ grub_ohci_pci_iter (int bus, int device, int func,
   if (! o)
     return 1;
 
-  /* Link in the OHCI.  */
-  o->next = ohci;
-  ohci = o;
   o->iobase = (grub_uint32_t *) base;
 
   /* Reserve memory for the HCCA.  */
@@ -189,6 +186,10 @@ grub_ohci_pci_iter (int bus, int device, int func,
   grub_dprintf ("ohci", "OHCI enable: 0x%02x\n",
 		(grub_ohci_readreg32 (o, GRUB_OHCI_REG_CONTROL) >> 6) & 3);
  
+  /* link to ohci now that initialisation is successful. */
+  o->next = ohci;
+  ohci = o;
+
   return 0;
 
  fail:
Index: bus/usb/uhci.c
===================================================================
--- bus/usb/uhci.c	(revision 2216)
+++ bus/usb/uhci.c	(working copy)
@@ -173,8 +173,6 @@ grub_uhci_pci_iter (int bus, int device, int func,
   if (! u)
     return 1;
 
-  u->next = uhci;
-  uhci = u;
   u->iobase = base & GRUB_UHCI_IOMASK;
   u->framelist = 0;
   u->qh = 0;
@@ -287,6 +285,10 @@ grub_uhci_pci_iter (int bus, int device, int func,
   }
 #endif
 
+  /* link to uhci now that initialisation is successful. */
+  u->next = uhci;
+  uhci = u;
+
   return 0;
 
  fail:
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to