Hi Patrick,

On 27/2/25 16:42, Patrick Venture wrote:
eth_hdr requires 2 byte alignment

Signed-off-by: Patrick Venture <vent...@google.com>
---
  hw/net/ftgmac100.c | 15 ++++++++++++---
  1 file changed, 12 insertions(+), 3 deletions(-)


@@ -1028,6 +1032,7 @@ static ssize_t ftgmac100_receive(NetClientState *nc, 
const uint8_t *buf,
  {
      FTGMAC100State *s = FTGMAC100(qemu_get_nic_opaque(nc));
      FTGMAC100Desc bd;
+    struct eth_header eth_hdr = {};
      uint32_t flags = 0;
      uint64_t addr;
      uint32_t crc;
@@ -1036,7 +1041,11 @@ static ssize_t ftgmac100_receive(NetClientState *nc, 
const uint8_t *buf,
      uint32_t buf_len;
      size_t size = len;
      uint32_t first = FTGMAC100_RXDES0_FRS;
-    uint16_t proto = be16_to_cpu(PKT_GET_ETH_HDR(buf)->h_proto);

The LD/ST API deals with unaligned fields, would that help?

    uint16_t proto = lduw_be_p(&PKT_GET_ETH_HDR(buf)->h_proto);

+    uint16_t proto;
+
+    memcpy(&eth_hdr, PKT_GET_ETH_HDR(buf),
+           (sizeof(eth_hdr) > len) ? len : sizeof(eth_hdr));
+    proto = be16_to_cpu(eth_hdr.h_proto);
      int max_frame_size = ftgmac100_max_frame_size(s, proto);


Reply via email to