Browse Source

[xhci] Fix length of allocated slot array

The xHCI slot ID is one-based, not zero-based.  Fix the length of the
xhci->slot[] array to account for this, and add assertions to check
that the hardware returns a valid slot ID in response to the Enable
Slot command.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 years ago
parent
commit
982b051cbc
1 changed files with 3 additions and 2 deletions
  1. 3
    2
      src/drivers/usb/xhci.c

+ 3
- 2
src/drivers/usb/xhci.c View File

@@ -2622,6 +2622,7 @@ static int xhci_device_open ( struct usb_device *usb ) {
2622 2622
 		rc = id;
2623 2623
 		goto err_enable_slot;
2624 2624
 	}
2625
+	assert ( ( id > 0 ) && ( id <= xhci->slots ) );
2625 2626
 	assert ( xhci->slot[id] == NULL );
2626 2627
 
2627 2628
 	/* Allocate and initialise structure */
@@ -2761,7 +2762,7 @@ static int xhci_bus_open ( struct usb_bus *bus ) {
2761 2762
 	int rc;
2762 2763
 
2763 2764
 	/* Allocate device slot array */
2764
-	xhci->slot = zalloc ( xhci->slots * sizeof ( xhci->slot[0] ) );
2765
+	xhci->slot = zalloc ( ( xhci->slots + 1 ) * sizeof ( xhci->slot[0] ) );
2765 2766
 	if ( ! xhci->slot ) {
2766 2767
 		rc = -ENOMEM;
2767 2768
 		goto err_slot_alloc;
@@ -2813,7 +2814,7 @@ static void xhci_bus_close ( struct usb_bus *bus ) {
2813 2814
 
2814 2815
 	/* Sanity checks */
2815 2816
 	assert ( xhci->slot != NULL );
2816
-	for ( i = 0 ; i < xhci->slots ; i++ )
2817
+	for ( i = 0 ; i <= xhci->slots ; i++ )
2817 2818
 		assert ( xhci->slot[i] == NULL );
2818 2819
 
2819 2820
 	xhci_stop ( xhci );

Loading…
Cancel
Save