]> Git Repo - qemu.git/commitdiff
hw/net/can/ctucan_core: Use stl_le_p to write to tx_buffers
authorPeter Maydell <[email protected]>
Tue, 10 Nov 2020 21:52:50 +0000 (22:52 +0100)
committerJason Wang <[email protected]>
Wed, 11 Nov 2020 12:34:36 +0000 (20:34 +0800)
Instead of casting an address within a uint8_t array to a
uint32_t*, use stl_le_p(). This handles possibly misaligned
addresses which would otherwise crash on some hosts.

Signed-off-by: Peter Maydell <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Pavel Pisa <[email protected]>
Tested-by: Pavel Pisa <[email protected]>
Signed-off-by: Jason Wang <[email protected]>
hw/net/can/ctucan_core.c

index f49c76261ca6bd04036966fa8694269ca71e5c64..d171c372e008ea5df25da6d3b39024a9b9eab2be 100644 (file)
@@ -303,11 +303,9 @@ void ctucan_mem_write(CtuCanCoreState *s, hwaddr addr, uint64_t val,
         addr -= CTU_CAN_FD_TXTB1_DATA_1;
         buff_num = addr / CTUCAN_CORE_TXBUFF_SPAN;
         addr %= CTUCAN_CORE_TXBUFF_SPAN;
-        addr &= ~3;
         if ((buff_num < CTUCAN_CORE_TXBUF_NUM) &&
-            (addr < sizeof(s->tx_buffer[buff_num].data))) {
-            uint32_t *bufp = (uint32_t *)(s->tx_buffer[buff_num].data + addr);
-            *bufp = cpu_to_le32(val);
+            ((addr + size) <= sizeof(s->tx_buffer[buff_num].data))) {
+            stn_le_p(s->tx_buffer[buff_num].data + addr, size, val);
         }
     } else {
         switch (addr & ~3) {
This page took 0.030775 seconds and 4 git commands to generate.