diff mbox series

[QEMU,master,v2,1/1] hw/net/can/xlnx-versal-canfd: Fix sorting of the tx queue

Message ID 20240531082605.2306976-1-Shivasagar.Myana@amd.com (mailing list archive)
State New, archived
Headers show
Series [QEMU,master,v2,1/1] hw/net/can/xlnx-versal-canfd: Fix sorting of the tx queue | expand

Commit Message

Shiva sagar Myana May 31, 2024, 8:26 a.m. UTC
Returning an uint32_t casted to a gint from g_cmp_ids causes the tx queue to
become wrongly sorted when executing g_slist_sort. Fix this by always
returning -1 or 1 from g_cmp_ids based on the ID comparison instead.
Also, if two message IDs are the same, sort them by using their index and
transmit the message at the lowest index first.

Signed-off-by: Shiva sagar Myana <Shivasagar.Myana@amd.com>
Reviewed-by: Francisco Iglesias <francisco.iglesias@amd.com>
---
ChangeLog:
v1->v2 : Subject line modified.

 hw/net/can/xlnx-versal-canfd.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Sai Pavan Boddu May 31, 2024, 9:47 a.m. UTC | #1
Hi Shiva,

>-----Original Message-----
>From: Shiva sagar Myana <Shivasagar.Myana@amd.com>
>Sent: Friday, May 31, 2024 1:56 PM
>To: Iglesias, Francisco <francisco.iglesias@amd.com>; jasowang@redhat.com;
>qemu-devel@nongnu.org; pisa@cmp.felk.cvut.cz
>Cc: peter.maydell@linaro.org; Boddu, Sai Pavan <sai.pavan.boddu@amd.com>;
>Myana, Shivasagar <Shivasagar.Myana@amd.com>
>Subject: [QEMU][master][PATCH v2 1/1] hw/net/can/xlnx-versal-canfd: Fix
>sorting of the tx queue
>
>Returning an uint32_t casted to a gint from g_cmp_ids causes the tx queue to
>become wrongly sorted when executing g_slist_sort. Fix this by always
>returning -1 or 1 from g_cmp_ids based on the ID comparison instead.
>Also, if two message IDs are the same, sort them by using their index and
>transmit the message at the lowest index first.
[Boddu, Sai Pavan] 

Reviewed-by: Sai Pavan Boddu <sai.pavan.boddu@amd.com>

FYI, this part of subject-line "[QEMU][master]" is not needed, as we target only one branch here.

Regards,
Sai Pavan
>
>Signed-off-by: Shiva sagar Myana <Shivasagar.Myana@amd.com>
>Reviewed-by: Francisco Iglesias <francisco.iglesias@amd.com>
>---
>ChangeLog:
>v1->v2 : Subject line modified.
>
> hw/net/can/xlnx-versal-canfd.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
>diff --git a/hw/net/can/xlnx-versal-canfd.c b/hw/net/can/xlnx-versal-canfd.c
>index 47a14cfe63..5f083c21e9 100644
>--- a/hw/net/can/xlnx-versal-canfd.c
>+++ b/hw/net/can/xlnx-versal-canfd.c
>@@ -1312,7 +1312,10 @@ static gint g_cmp_ids(gconstpointer data1,
>gconstpointer data2)
>     tx_ready_reg_info *tx_reg_1 = (tx_ready_reg_info *) data1;
>     tx_ready_reg_info *tx_reg_2 = (tx_ready_reg_info *) data2;
>
>-    return tx_reg_1->can_id - tx_reg_2->can_id;
>+    if (tx_reg_1->can_id == tx_reg_2->can_id) {
>+        return (tx_reg_1->reg_num < tx_reg_2->reg_num) ? -1 : 1;
>+    }
>+    return (tx_reg_1->can_id < tx_reg_2->can_id) ? -1 : 1;
> }
>
> static void free_list(GSList *list)
>--
>2.37.6
diff mbox series

Patch

diff --git a/hw/net/can/xlnx-versal-canfd.c b/hw/net/can/xlnx-versal-canfd.c
index 47a14cfe63..5f083c21e9 100644
--- a/hw/net/can/xlnx-versal-canfd.c
+++ b/hw/net/can/xlnx-versal-canfd.c
@@ -1312,7 +1312,10 @@  static gint g_cmp_ids(gconstpointer data1, gconstpointer data2)
     tx_ready_reg_info *tx_reg_1 = (tx_ready_reg_info *) data1;
     tx_ready_reg_info *tx_reg_2 = (tx_ready_reg_info *) data2;
 
-    return tx_reg_1->can_id - tx_reg_2->can_id;
+    if (tx_reg_1->can_id == tx_reg_2->can_id) {
+        return (tx_reg_1->reg_num < tx_reg_2->reg_num) ? -1 : 1;
+    }
+    return (tx_reg_1->can_id < tx_reg_2->can_id) ? -1 : 1;
 }
 
 static void free_list(GSList *list)