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
 		rc = id;
2622
 		rc = id;
2623
 		goto err_enable_slot;
2623
 		goto err_enable_slot;
2624
 	}
2624
 	}
2625
+	assert ( ( id > 0 ) && ( id <= xhci->slots ) );
2625
 	assert ( xhci->slot[id] == NULL );
2626
 	assert ( xhci->slot[id] == NULL );
2626
 
2627
 
2627
 	/* Allocate and initialise structure */
2628
 	/* Allocate and initialise structure */
2761
 	int rc;
2762
 	int rc;
2762
 
2763
 
2763
 	/* Allocate device slot array */
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
 	if ( ! xhci->slot ) {
2766
 	if ( ! xhci->slot ) {
2766
 		rc = -ENOMEM;
2767
 		rc = -ENOMEM;
2767
 		goto err_slot_alloc;
2768
 		goto err_slot_alloc;
2813
 
2814
 
2814
 	/* Sanity checks */
2815
 	/* Sanity checks */
2815
 	assert ( xhci->slot != NULL );
2816
 	assert ( xhci->slot != NULL );
2816
-	for ( i = 0 ; i < xhci->slots ; i++ )
2817
+	for ( i = 0 ; i <= xhci->slots ; i++ )
2817
 		assert ( xhci->slot[i] == NULL );
2818
 		assert ( xhci->slot[i] == NULL );
2818
 
2819
 
2819
 	xhci_stop ( xhci );
2820
 	xhci_stop ( xhci );

Loading…
Cancel
Save