qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: qemu-devel@nongnu.org, peter.maydell@linaro.org
Cc: Qiang Liu <cyruscyliu@gmail.com>, Jason Wang <jasowang@redhat.com>
Subject: [PULL 08/11] hw/net/can/xlnx-zynqmp-can: fix assertion failures in transfer_fifo()
Date: Thu,  2 Feb 2023 14:21:23 +0800	[thread overview]
Message-ID: <20230202062126.67550-9-jasowang@redhat.com> (raw)
In-Reply-To: <20230202062126.67550-1-jasowang@redhat.com>

From: Qiang Liu <cyruscyliu@gmail.com>

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
Reported-by: Qiang Liu <cyruscyliu@gmail.com>
Signed-off-by: Qiang Liu <cyruscyliu@gmail.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 hw/net/can/xlnx-zynqmp-can.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/hw/net/can/xlnx-zynqmp-can.c b/hw/net/can/xlnx-zynqmp-can.c
index e93e6c5..55d3221 100644
--- a/hw/net/can/xlnx-zynqmp-can.c
+++ b/hw/net/can/xlnx-zynqmp-can.c
@@ -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++) {
-- 
2.7.4



  parent reply	other threads:[~2023-02-02  6:22 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-02  6:21 [PULL 00/11] Net patches Jason Wang
2023-02-02  6:21 ` [PULL 01/11] net: Move the code to collect available NIC models to a separate function Jason Wang
2023-02-02  6:21 ` [PULL 02/11] net: Restore printing of the help text with "-nic help" Jason Wang
2023-02-02  6:21 ` [PULL 03/11] net: Replace "Supported NIC models" with "Available NIC models" Jason Wang
2023-02-02  6:21 ` [PULL 04/11] hw/net/lan9118: log [read|write]b when mode_16bit is enabled rather than abort Jason Wang
2023-02-02  6:21 ` [PULL 05/11] hw/net/vmxnet3: allow VMXNET3_MAX_MTU itself as a value Jason Wang
2023-02-02  6:21 ` [PULL 06/11] net: Increase L2TPv3 buffer to fit jumboframes Jason Wang
2023-02-02  6:21 ` [PULL 07/11] vmnet: stop recieving events when VM is stopped Jason Wang
2023-02-02  6:21 ` Jason Wang [this message]
2023-02-02  6:21 ` [PULL 09/11] tests/qtest: netdev: test stream and dgram backends Jason Wang
2023-02-02  6:21 ` [PULL 10/11] net: stream: add a new option to automatically reconnect Jason Wang
2023-02-02  6:21 ` [PULL 11/11] vdpa: fix VHOST_BACKEND_F_IOTLB_ASID flag check Jason Wang
2023-02-04 14:57 ` [PULL 00/11] Net patches Peter Maydell
2023-02-04 20:09   ` Laurent Vivier
2023-02-05 12:36     ` Peter Maydell
2023-02-06  8:23       ` Laurent Vivier
2023-02-13  3:59         ` Jason Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230202062126.67550-9-jasowang@redhat.com \
    --to=jasowang@redhat.com \
    --cc=cyruscyliu@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).