Skip to contentSkip to conversation

hw/net/can/xlnx-zynqmp-can: fix assertion failures in transfer_fifo()

PATCH Applied Qiang Liu 2 participants 2 messages Jan 9, 2023 – Jan 19, 2023 Arm/Zynq architecture

lore
Share & tools
lore

Qiang Liu

author
#0 lore raw

PATCH 1/1 hw/net/can/xlnx-zynqmp-can: fix assertion failures in transfer_fifo()

Check fifos before poping data from and pushing data into it.

Fixes 98e5d7a2b726 ("hw/net/can: Introduce Xilinx ZynqMP CAN controller")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1425
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1427

---
 hw/net/can/xlnx-zynqmp-can.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
hw/net/can/xlnx-zynqmp-can.c +8 -1
index e93e6c5e19..55d3221b49 100644
@@ -451,6 +451,12 @@ static void transfer_fifo(XlnxZynqMPCANState *s, Fifo32 *fifo)
     }
 
     while (!fifo32_is_empty(fifo)) {
+        if (fifo32_num_used(fifo) < (4 * CAN_FRAME_SIZE)) {
+            g_autofree char *path = object_get_canonical_path(OBJECT(s));
+            qemu_log_mask(LOG_GUEST_ERROR, "%s: data left in the fifo is not"
+                          " enough for transfer.\n", path);
+            break;
+        }
         for (i = 0; i < CAN_FRAME_SIZE; i++) {
             data[i] = fifo32_pop(fifo);
         }
@@ -463,7 +469,8 @@ static void transfer_fifo(XlnxZynqMPCANState *s, Fifo32 *fifo)
              * acknowledged. The XlnxZynqMPCAN core receives any message
              * that it transmits.
              */
-            if (fifo32_is_full(&s->rx_fifo)) {
+            if (fifo32_is_full(&s->rx_fifo) ||
+                    (fifo32_num_free(&s->rx_fifo) < (4 * CAN_FRAME_SIZE))) {
                 ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXOFLW, 1);
             } else {
                 for (i = 0; i < CAN_FRAME_SIZE; i++) {
Signature · 1 line
2.25.1
Applied
#1 lore raw
Quoted 7 lines · Qiang Liu

Check fifos before poping data from and pushing data into it.

Fixes 98e5d7a2b726 ("hw/net/can: Introduce Xilinx ZynqMP CAN controller")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1425
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1427

Applied.

Thanks

Quoted 31 lines
---
  hw/net/can/xlnx-zynqmp-can.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
hw/net/can/xlnx-zynqmp-can.c +8 -1
index e93e6c5e19..55d3221b49 100644
@@ -451,6 +451,12 @@ static void transfer_fifo(XlnxZynqMPCANState *s, Fifo32 *fifo)
      }
 
      while (!fifo32_is_empty(fifo)) {
+        if (fifo32_num_used(fifo) < (4 * CAN_FRAME_SIZE)) {
+            g_autofree char *path = object_get_canonical_path(OBJECT(s));
+            qemu_log_mask(LOG_GUEST_ERROR, "%s: data left in the fifo is not"
+                          " enough for transfer.\n", path);
+            break;
+        }
          for (i = 0; i < CAN_FRAME_SIZE; i++) {
              data[i] = fifo32_pop(fifo);
          }
@@ -463,7 +469,8 @@ static void transfer_fifo(XlnxZynqMPCANState *s, Fifo32 *fifo)
               * acknowledged. The XlnxZynqMPCAN core receives any message
               * that it transmits.
               */
-            if (fifo32_is_full(&s->rx_fifo)) {
+            if (fifo32_is_full(&s->rx_fifo) ||
+                    (fifo32_num_free(&s->rx_fifo) < (4 * CAN_FRAME_SIZE))) {
                  ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXOFLW, 1);
              } else {
                  for (i = 0; i < CAN_FRAME_SIZE; i++) {