aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2023-01-19 18:21:50 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2023-01-19 18:21:50 +0000
commitb36b14beda4ff7ecbb906ada756141f76fcb81aa (patch)
treed6d70a3e7cb059012e63239fe64a59febfbc0233 /usr.sbin
parent05187f2ffc79e5959762ab8ce7067b7b8a1cdfd9 (diff)
downloadsrc-b36b14beda4ff7ecbb906ada756141f76fcb81aa.tar.gz
src-b36b14beda4ff7ecbb906ada756141f76fcb81aa.zip
bhyve: Avoid triggering false -Wfree-nonheap-object warnings.
XHCI port and slot numbers are 1-based rather than 0-based. To handle this, bhyve was subtracting one item from the pointers saved in the softc so that index 1 accessed index 0 of the allocated array. However, this is UB and confused GCC 12. The compiler noticed that the calls to free() were using an offset and emitted a warning. Rather than storing UB pointers in the softc, push the decrement operation into the existing macros that wrap accesses to the relevant arrays. Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D36829
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/bhyve/pci_xhci.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/usr.sbin/bhyve/pci_xhci.c b/usr.sbin/bhyve/pci_xhci.c
index 5bc9498a4eb4..1eceb6fe0fd3 100644
--- a/usr.sbin/bhyve/pci_xhci.c
+++ b/usr.sbin/bhyve/pci_xhci.c
@@ -290,10 +290,10 @@ struct pci_xhci_softc {
};
-/* 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 @@ pci_xhci_parse_devices(struct pci_xhci_softc *sc, nvlist_t *nvl)
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 @@ pci_xhci_parse_devices(struct pci_xhci_softc *sc, nvlist_t *nvl)
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 @@ bad:
free(XHCI_DEVINST_PTR(sc, i));
}
- free(sc->devices + 1);
- free(sc->slots + 1);
+ free(sc->devices);
+ free(sc->slots);
return (-1);
}