Skip to content

Commit 5cc389a

Browse files
xiaoguangwulijinxia
authored andcommitted
DM USB: xHCI: limit bus and port numbers of xHCI
Currently the maximum number of bus and port for xHCI are both set to 255, it is theoretically possible but in fact not neccessary. This patch changes those two values to be more proper: 4 buses and 20 ports. Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com> Reviewed-by: Liang Yang <liang3.yang@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
1 parent 2abec44 commit 5cc389a

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

devicemodel/hw/pci/xhci.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ struct pci_xhci_vdev {
373373
int (*excap_write)(struct pci_xhci_vdev *, uint64_t, uint64_t);
374374
int usb2_port_start;
375375
int usb3_port_start;
376-
uint8_t *native_assign_ports[USB_NATIVE_NUM_BUS];
376+
uint8_t native_assign_ports[USB_NATIVE_NUM_BUS][USB_NATIVE_NUM_PORT];
377377
struct timespec mf_prev_time; /* previous time of accessing MFINDEX */
378378
};
379379

@@ -500,8 +500,7 @@ pci_xhci_native_usb_dev_conn_cb(void *hci_data, void *dev_data)
500500
UPRINTF(LDBG, "%04x:%04x %d-%d connecting.\r\n",
501501
di->vid, di->pid, di->bus, di->port);
502502

503-
if (!xdev->native_assign_ports[di->bus] ||
504-
!xdev->native_assign_ports[di->bus][di->port]) {
503+
if (!xdev->native_assign_ports[di->bus][di->port]) {
505504
UPRINTF(LDBG, "%04x:%04x %d-%d doesn't belong to this vm, bye."
506505
"\r\n", di->vid, di->pid, di->bus, di->port);
507506
goto errout;
@@ -3361,15 +3360,6 @@ pci_xhci_parse_bus_port(struct pci_xhci_vdev *xdev, char *opts)
33613360
goto errout;
33623361
}
33633362

3364-
if (!xdev->native_assign_ports[bus]) {
3365-
xdev->native_assign_ports[bus] = calloc(USB_NATIVE_NUM_PORT,
3366-
sizeof(uint8_t));
3367-
if (!xdev->native_assign_ports[bus]) {
3368-
rc = -3;
3369-
goto errout;
3370-
}
3371-
}
3372-
33733363
xdev->native_assign_ports[bus][port] = 1;
33743364
errout:
33753365
if (rc)

devicemodel/include/usb_core.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ enum USB_ERRCODE {
223223
#define NATIVE_USBSYS_DEVDIR "/sys/bus/usb/devices"
224224
#define NATIVE_USB2_SPEED "480"
225225
#define NATIVE_USB3_SPEED "5000"
226-
#define USB_NATIVE_NUM_PORT 255
227-
#define USB_NATIVE_NUM_BUS 255
226+
#define USB_NATIVE_NUM_PORT 20
227+
#define USB_NATIVE_NUM_BUS 4
228228

229229
extern int usb_log_level;
230230
inline int usb_get_log_level(void) { return usb_log_level; }

0 commit comments

Comments
 (0)