qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw/net: npcm7xx_emc: fix alignment to eth_hdr
@ 2025-02-27 15:40 Patrick Venture
  2025-02-27 15:52 ` Peter Maydell
  0 siblings, 1 reply; 7+ messages in thread
From: Patrick Venture @ 2025-02-27 15:40 UTC (permalink / raw)
  To: peter.maydell
  Cc: kfting, wuhaotsh, jasowang, qemu-arm, qemu-devel, Patrick Venture

'const struct eth_header', which requires 2 byte alignment

Signed-off-by: Patrick Venture <venture@google.com>
---
 hw/net/npcm7xx_emc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/hw/net/npcm7xx_emc.c b/hw/net/npcm7xx_emc.c
index e06f652629..11ed4a9e6a 100644
--- a/hw/net/npcm7xx_emc.c
+++ b/hw/net/npcm7xx_emc.c
@@ -424,7 +424,12 @@ static bool emc_can_receive(NetClientState *nc)
 static bool emc_receive_filter1(NPCM7xxEMCState *emc, const uint8_t *buf,
                                 size_t len, const char **fail_reason)
 {
-    eth_pkt_types_e pkt_type = get_eth_packet_type(PKT_GET_ETH_HDR(buf));
+    struct eth_header eth_hdr = {};
+    eth_pkt_types_e pkt_type;
+
+    memcpy(&eth_hdr, PKT_GET_ETH_HDR(buf),
+           (sizeof(eth_hdr) > len) ? len : sizeof(eth_hdr));
+    pkt_type = get_eth_packet_type(&eth_hdr);
 
     switch (pkt_type) {
     case ETH_PKT_BCAST:
-- 
2.48.1.658.g4767266eb4-goog



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-02-27 18:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-27 15:40 [PATCH] hw/net: npcm7xx_emc: fix alignment to eth_hdr Patrick Venture
2025-02-27 15:52 ` Peter Maydell
2025-02-27 15:55   ` Patrick Venture
2025-02-27 16:01     ` Peter Maydell
2025-02-27 16:08       ` Patrick Venture
2025-02-27 18:12         ` Patrick Venture
2025-02-27 18:44           ` Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).