diff --git a/usr.sbin/bhyve/pci_xhci.c b/usr.sbin/bhyve/pci_xhci.c --- a/usr.sbin/bhyve/pci_xhci.c +++ b/usr.sbin/bhyve/pci_xhci.c @@ -290,10 +290,10 @@ }; -/* portregs and devices arrays are set up to start from idx=1 */ -#define XHCI_PORTREG_PTR(x,n) &(x)->portregs[(n)] -#define XHCI_DEVINST_PTR(x,n) (x)->devices[(n)] -#define XHCI_SLOTDEV_PTR(x,n) (x)->slots[(n)] +/* port and slot numbering start from 1 */ +#define XHCI_PORTREG_PTR(x,n) &((x)->portregs[(n) - 1]) +#define XHCI_DEVINST_PTR(x,n) ((x)->devices[(n) - 1]) +#define XHCI_SLOTDEV_PTR(x,n) ((x)->slots[(n) - 1]) #define XHCI_HALTED(sc) ((sc)->opregs.usbsts & XHCI_STS_HCH) @@ -2738,10 +2738,6 @@ sc->devices = calloc(XHCI_MAX_DEVS, sizeof(struct pci_xhci_dev_emu *)); sc->slots = calloc(XHCI_MAX_SLOTS, sizeof(struct pci_xhci_dev_emu *)); - /* port and slot numbering start from 1 */ - sc->devices--; - sc->slots--; - ndevices = 0; slots_nvl = find_relative_config_node(nvl, "slot"); @@ -2835,7 +2831,6 @@ portsfinal: sc->portregs = calloc(XHCI_MAX_DEVS, sizeof(struct pci_xhci_portregs)); - sc->portregs--; if (ndevices > 0) { for (i = 1; i <= XHCI_MAX_DEVS; i++) { @@ -2851,8 +2846,8 @@ free(XHCI_DEVINST_PTR(sc, i)); } - free(sc->devices + 1); - free(sc->slots + 1); + free(sc->devices); + free(sc->slots); return (-1); }