git: 32b21dd2719f - main - bhyve: Appease warning about a potentially unaligned pointer.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 29 Nov 2022 01:11:00 UTC
The branch main has been updated by jhb:
URL: https://cgit.FreeBSD.org/src/commit/?id=32b21dd2719f87811b66deeeb513acf7067f8fac
commit 32b21dd2719f87811b66deeeb513acf7067f8fac
Author: John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-11-29 01:10:07 +0000
Commit: John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-11-29 01:10:07 +0000
bhyve: Appease warning about a potentially unaligned pointer.
When initializing the device model for a PCI pass through device that
uses MSI-X, bhyve reads the MSI-X capability from the real device to
save a copy in the emulated PCI config space. It also saves a copy in
a local struct msixcap on the stack. Since struct msixcap is packed,
GCC complains that casting a pointer to the struct to a uint32_t
pointer may result in an unaligned pointer.
This path is not performance critical, so to appease the compiler,
simply change the pointer to a char * and use memcpy to copy the 4
bytes read in each iteration of the loop.
Reviewed by: corvink, bz, markj
Differential Revision: https://reviews.freebsd.org/D37490
---
usr.sbin/bhyve/pci_passthru.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/usr.sbin/bhyve/pci_passthru.c b/usr.sbin/bhyve/pci_passthru.c
index 3f5cbe221bd6..b4a8b623eca9 100644
--- a/usr.sbin/bhyve/pci_passthru.c
+++ b/usr.sbin/bhyve/pci_passthru.c
@@ -212,7 +212,7 @@ cfginitmsi(struct passthru_softc *sc)
struct pcisel sel;
struct pci_devinst *pi;
struct msixcap msixcap;
- uint32_t *msixcap_ptr;
+ char *msixcap_ptr;
pi = sc->psc_pi;
sel = sc->psc_sel;
@@ -249,15 +249,15 @@ cfginitmsi(struct passthru_softc *sc)
*/
sc->psc_msix.capoff = ptr;
caplen = 12;
- msixcap_ptr = (uint32_t*) &msixcap;
+ msixcap_ptr = (char *)&msixcap;
capptr = ptr;
while (caplen > 0) {
u32 = read_config(&sel, capptr, 4);
- *msixcap_ptr = u32;
+ memcpy(msixcap_ptr, &u32, 4);
pci_set_cfgdata32(pi, capptr, u32);
caplen -= 4;
capptr += 4;
- msixcap_ptr++;
+ msixcap_ptr += 4;
}
}
ptr = read_config(&sel, ptr + PCICAP_NEXTPTR, 1);