git: cee36581281d - stable/13 - bhyve: Appease warning about a potentially unaligned pointer.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Thu, 26 Jan 2023 20:27:17 UTC
The branch stable/13 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=cee36581281d4b3ce67e14dd16178d9543b5b64f

commit cee36581281d4b3ce67e14dd16178d9543b5b64f
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-11-29 01:10:07 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2023-01-26 20:24:09 +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
    
    (cherry picked from commit 32b21dd2719f87811b66deeeb513acf7067f8fac)
---
 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 049b49b67c60..285874f3925d 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);