From nobody Thu Jan 26 22:35:06 2023 X-Original-To: dev-commits-src-all@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 4P2wWb1075z3cCXk; Thu, 26 Jan 2023 22:35:07 +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 4P2wWZ5D8yz4Ds2; Thu, 26 Jan 2023 22:35:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674772506; 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=FryZtG12t3kZcRMvbS1yLbO/9XkunKI/zjSjkV5BjKk=; b=kA/IIhWSp7cVjN2TTXASx1VR5ulX5fPrdGNyZVvwnI93f/Td1Xzz9d/Q+f+bWvG52PLkpe 4npek8onogSvJaQWkgQzAwpOrVtA0QZRbtwx3dFOAshgblFfTt9iBrvXQuIIbwUYgUWK++ +Ayj+BFL/66t1NupndNo3H5yBzgzM2MB4uhy0mJPodZN+AJeinL+NBaTlJw4UQxTEUnH/W D7XAE3xhNBKa5gm5ionXM8nHiI/VkBGbYEObwZawn8eiPFuMF6fdielJcf9iswWi8BfU/l l7iceqM5ySOGgCaliqf8lTBZrOcuCw2rQ2kmnYDvKP+LdIJk+WyOLmVGIQz2qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674772506; 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=FryZtG12t3kZcRMvbS1yLbO/9XkunKI/zjSjkV5BjKk=; b=Ko8/ge11fi2lAlonqnF6puO+BYbv4B11sXcFBif8FiWNE0cX8XZRk00bQSST8hHF1848Jl EXitcPTucNGmN1XVYo57Gt4MHjjwPn3b/Vfb2DtJZL6kHLOAiTwIp8LE49BI3VPt4g1mi0 gxlG1hMR1fx08Wg6FRuk8T8QR/FWwc57nKYsq4F47/hOLwRIxnsA8+a9WliHcu+ghP8k0F +FNndj0czZ49eDCnWvyPob2aF/u91HiYILu1P+rX1lmquXiD7K65dPTYP4SNwFZPEvwITK BtkSWHtxKKClgjMl5Ay+5p6IxTQnQtd70vwzCS9YpYxgqMFwJhW0FxNj0ycSyw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674772506; a=rsa-sha256; cv=none; b=W/ZVs9Zn9PunqcpmpX2r1TwxLIRXorlIckYE9sAdgM7MfsOYvdCOdnHN5ei7V4flhejfat aCsVxupQsWU/NMP+Ikk1ouhh9Og0f1jyqePI7eCn0CotmH9e7TC9KqJr46XmfVI5wZrX20 unj9zDFYQ5Th+CsdkY7Nhqbnb8h0s7rumgvmV8LfgBx2tTGFmUZhnnCSWHj7nsO8n6saFI hc6XBoTjoUjx7GmLaD9858IcUI0z0cT8iINgA8r5j/CuXcni/9hfwlOJkryolHXzyV0Uv0 92qhexNaeVBCnwUQCC8At0KLU8+3rW4CUKbIHilTPbkFP6TdP+z4L/H5VllgGg== 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 4P2wWZ4GQ4zmdM; Thu, 26 Jan 2023 22:35:06 +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 30QMZ6sq051669; Thu, 26 Jan 2023 22:35:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30QMZ6fp051668; Thu, 26 Jan 2023 22:35:06 GMT (envelope-from git) Date: Thu, 26 Jan 2023 22:35:06 GMT Message-Id: <202301262235.30QMZ6fp051668@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 411ea77fed69 - stable/13 - bhyve: Avoid triggering false -Wfree-nonheap-object warnings. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 411ea77fed696c6e93696b13d633a49317f05113 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=411ea77fed696c6e93696b13d633a49317f05113 commit 411ea77fed696c6e93696b13d633a49317f05113 Author: John Baldwin AuthorDate: 2023-01-19 18:21:50 +0000 Commit: John Baldwin CommitDate: 2023-01-26 22:18:44 +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 (cherry picked from commit b36b14beda4ff7ecbb906ada756141f76fcb81aa) --- 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); }