[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 17/17] hw/net/can/ctucan_core: Use stl_le_p to write to tx_buffers
From: |
Jason Wang |
Subject: |
[PULL 17/17] hw/net/can/ctucan_core: Use stl_le_p to write to tx_buffers |
Date: |
Wed, 11 Nov 2020 21:11:41 +0800 |
From: Peter Maydell <peter.maydell@linaro.org>
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 <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Tested-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
hw/net/can/ctucan_core.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/hw/net/can/ctucan_core.c b/hw/net/can/ctucan_core.c
index f49c762..d171c37 100644
--- a/hw/net/can/ctucan_core.c
+++ b/hw/net/can/ctucan_core.c
@@ -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) {
--
2.7.4
- [PULL 05/17] Fix the qemu crash when guest shutdown in COLO mode, (continued)
- [PULL 05/17] Fix the qemu crash when guest shutdown in COLO mode, Jason Wang, 2020/11/11
- [PULL 08/17] net/colo-compare.c: Fix compare_timeout format issue, Jason Wang, 2020/11/11
- [PULL 09/17] net/colo-compare.c: Change the timer clock type, Jason Wang, 2020/11/11
- [PULL 10/17] net/colo-compare.c: Add secondary old packet detection, Jason Wang, 2020/11/11
- [PULL 11/17] net/colo-compare.c: Increase default queued packet scan frequency, Jason Wang, 2020/11/11
- [PULL 13/17] net/l2tpv3: Remove redundant check in net_init_l2tpv3(), Jason Wang, 2020/11/11
- [PULL 12/17] net: remove an assert call in eth_get_gso_type, Jason Wang, 2020/11/11
- [PULL 14/17] hw/net/can/ctucan: Don't allow guest to write off end of tx_buffer, Jason Wang, 2020/11/11
- [PULL 15/17] hw/net/can/ctucan: Avoid unused value in ctucan_send_ready_buffers(), Jason Wang, 2020/11/11
- [PULL 16/17] hw/net/can/ctucan_core: Handle big-endian hosts, Jason Wang, 2020/11/11
- [PULL 17/17] hw/net/can/ctucan_core: Use stl_le_p to write to tx_buffers,
Jason Wang <=
- Re: [PULL 00/17] Net patches, Peter Maydell, 2020/11/11