From nobody Thu Jan 19 18:22:10 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NyWDy5mFKz310PX; Thu, 19 Jan 2023 18:22:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NyWDy5Mnmz42ZW; Thu, 19 Jan 2023 18:22:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674152530; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cqjsaOtPFFdHsN8DI73HxfgX5h6bhC1FEiNB9Hzvgdo=; b=v/1rWx9hHo/ZaCaCLOh+AZxr/IRM4PAZljotkdW+g07C77F4dqeqAERm9/un0coOwxwNaZ Ul3GVTqaWAsxIipK0HSSJZypR/NFwlkMffcUDskNpCIvp3W5kCLEhzOcuzkr8cFboq0HWP tUWFdS5p5mhMMLgFty1GiKrfkPdpIFD2XpZ/lSceV1x5IjpFZDUCgM0LnJfoOewHekVJKJ eEFpVMYrCCtJq/hD3PsRG0YpdSYoEZDDATLG2214WEVxE2MPXW6dLWM3rzvG3Ckgq9jc0e BPVEfOqzadwXS1VjapewyPHvJzlDDyQQe27QBoA2USf7urLxXoLj4at5E+Y2EQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674152530; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cqjsaOtPFFdHsN8DI73HxfgX5h6bhC1FEiNB9Hzvgdo=; b=NOsZ+60/4Zw++APhjcSTpNaathq2wD1qkzmkFV2XJgDRUpvmARN/H2SHU/+fYV/rSVYFzv j4mrpV1F8pCoj7UW0Bd5LWNfOMvNoEYAFhglsSqbeNfFvGfJddB0ygxYNa2btOFcF0lA3r 0wMGG2l92fxyByYngK/zPNxe6ZYh5v1dYW0NiUfntNETUMbh68YCGV2DyW+MewzPD+rMlM wNq7XlpdVsK9ieEXbiwHYiAxADbXHvAiy9yf2GVRLupLWuVVTih6i5NC69KCF7Il6tSx6z 3GW3brs36/WGDzLx5NMb7+fbkzwUug2Vb92dOkn0gcXKatdsEydJ+kLMQhYnEg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674152530; a=rsa-sha256; cv=none; b=m6QxXXRMkEhEk7avQk4R8ZcEUWXRoM+ySivtFfHwAg/2XiI1JgvBF5cLUcLJNLDF10VLgy VQBz+vC2duQM3sb0GmzfsSL6knCJ2JvDJDdwbCXuPu2tmQIaUWmmFy0mK/HskxuBq+0EG5 rSUyGSoaSncM3xLdAMmADCoCrb5b2qpZfVhmGadFkqnc9UNLiOdGjhEusZuGNxN/RDCUrH kes8/JxAZpseWhNZ9UhMXr97S1nmbs/waLti4GzQ/NLfq9tcC7SvhhKHJ5yhfBHVqoSJK/ jLUWDhRLaqti6pX/FEOoCymisAss9VTkMBQS1o9s5q0sKdin/gTtxwAZFFuoLQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NyWDy49Jcz116b; Thu, 19 Jan 2023 18:22:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30JIMAE5067445; Thu, 19 Jan 2023 18:22:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30JIMAIT067444; Thu, 19 Jan 2023 18:22:10 GMT (envelope-from git) Date: Thu, 19 Jan 2023 18:22:10 GMT Message-Id: <202301191822.30JIMAIT067444@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: b36b14beda4f - main - bhyve: Avoid triggering false -Wfree-nonheap-object warnings. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b36b14beda4ff7ecbb906ada756141f76fcb81aa Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=b36b14beda4ff7ecbb906ada756141f76fcb81aa commit b36b14beda4ff7ecbb906ada756141f76fcb81aa Author: John Baldwin AuthorDate: 2023-01-19 18:21:50 +0000 Commit: John Baldwin CommitDate: 2023-01-19 18:21:50 +0000 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 --- usr.sbin/bhyve/pci_xhci.c | 17 ++++++----------- 1 file 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); }