Re: [PATCH] Link usb controller struct only when initialised

2009-06-08 Thread Vladimir 'phcoder' Serbinenko
Commited with small stylistic change: comments start with an uppercase
letter and end with 2 spaces

On Sun, Jun 7, 2009 at 8:37 PM, Oliver Henshawoliver.hens...@gmail.com wrote:
 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

 ___
 Grub-devel mailing list
 Grub-devel@gnu.org
 http://lists.gnu.org/mailman/listinfo/grub-devel





-- 
Regards
Vladimir 'phcoder' Serbinenko


___
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] Link usb controller struct only when initialised

2009-06-08 Thread Pavel Roskin
On Tue, 2009-06-09 at 01:57 +0200, Vladimir 'phcoder' Serbinenko wrote:
 Commited with small stylistic change: comments start with an uppercase
 letter and end with 2 spaces

Thanks!

By the way, it would be nice to rewrite uhci.c and ohci.c using GRUB
lists (include/grub/list.h).  And rewriting usb_keyboard.c would fix the
crash when the USB keyboard is missing.

-- 
Regards,
Pavel Roskin


___
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Link usb controller struct only when initialised

2009-06-07 Thread Oliver Henshaw
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