From 6a0e7a53067c17e1ce04bfba0bea7d447425a2b2 Mon Sep 17 00:00:00 2001 From: Benjamin David Lunt Date: Sun, 12 Mar 2023 16:40:02 -0700 Subject: [PATCH] Allow a usb port number to be more than one digit Also fixed an error with xhci and the save/restore Bochs environment --- bochs/iodev/usb/usb_xhci.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bochs/iodev/usb/usb_xhci.cc b/bochs/iodev/usb/usb_xhci.cc index 9fa8f45f2..ac46b81fc 100644 --- a/bochs/iodev/usb/usb_xhci.cc +++ b/bochs/iodev/usb/usb_xhci.cc @@ -148,11 +148,8 @@ static Bit8u ext_caps[EXT_CAPS_SIZE] = { // builtin configuration handling functions Bit32s usb_xhci_options_parser(const char *context, int num_params, char *params[]) { - // try to catch an out of range port number - Bit32s max_ports = SIM->get_param_num(BXPN_XHCI_N_PORTS)->get(); - if (max_ports < 0) - max_ports = USB_XHCI_PORTS; - + int max_ports; + if (!strcmp(params[0], "usb_xhci")) { bx_list_c *base = (bx_list_c*) SIM->get_param(BXPN_USB_XHCI); for (int i = 1; i < num_params; i++) { @@ -166,10 +163,13 @@ Bit32s usb_xhci_options_parser(const char *context, int num_params, char *params else BX_PANIC(("%s: unknown parameter '%s' for usb_xhci: model=", context, ¶ms[i][6])); } else if (!strncmp(params[i], "n_ports=", 8)) { - max_ports = atol(¶ms[i][8]); - SIM->get_param_num(BXPN_XHCI_N_PORTS)->set(max_ports); + max_ports = (int) strtol(¶ms[i][8], NULL, 10); + if ((max_ports >= 2) && (max_ports <= USB_XHCI_PORTS_MAX) && !(max_ports & 1)) + SIM->get_param_num(BXPN_XHCI_N_PORTS)->set(max_ports); + else + BX_PANIC(("%s: n_ports= must be at least 2, no more than %d, and an even number.", context, USB_XHCI_PORTS_MAX)); } else if (!strncmp(params[i], "port", 4) || !strncmp(params[i], "options", 7)) { - if (SIM->parse_usb_port_params(context, params[i], max_ports, base) < 0) { + if (SIM->parse_usb_port_params(context, params[i], USB_XHCI_PORTS_MAX, base) < 0) { return -1; } } else {