All of lore.kernel.org
 help / color / mirror / Atom feed
From: Evgeny Kolmakov <randomjack94dev@gmail.com>
To: qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, Evgeny Kolmakov <randomjack94dev@gmail.com>
Subject: [PATCH] hw/dma/soc_dma: Replace if-else chain with array lookup
Date: Sat, 20 Jun 2026 20:13:18 +0300	[thread overview]
Message-ID: <20260620171318.24189-1-randomjack94dev@gmail.com> (raw)

Refactor transfer_fn assignment in soc_dma_ch_update()
via array lookup as suggested by the TODO comment.

Signed-off-by: Evgeny Kolmakov <randomjack94dev@gmail.com>
---
 hw/dma/soc_dma.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/hw/dma/soc_dma.c b/hw/dma/soc_dma.c
index d5c52b804f..a5b1ef9f61 100644
--- a/hw/dma/soc_dma.c
+++ b/hw/dma/soc_dma.c
@@ -163,6 +163,16 @@ static inline enum soc_dma_port_type soc_dma_ch_update_type(
 
 void soc_dma_ch_update(struct soc_dma_ch_s *ch)
 {
+    static const soc_dma_transfer_t transfer_fn[2][2] = {
+        [soc_dma_port_mem] = {
+            [soc_dma_port_mem] = transfer_mem2mem,
+            [soc_dma_port_fifo] = transfer_mem2fifo,
+        },
+        [soc_dma_port_fifo] = {
+            [soc_dma_port_mem] = transfer_fifo2mem,
+            [soc_dma_port_fifo] = transfer_fifo2fifo,
+        },
+    };
     enum soc_dma_port_type src, dst;
 
     src = soc_dma_ch_update_type(ch, 0);
@@ -171,21 +181,16 @@ void soc_dma_ch_update(struct soc_dma_ch_s *ch)
         ch->transfer_fn = ch->dma->transfer_fn;
         return;
     }
-    dst = soc_dma_ch_update_type(ch, 1);
 
-    /* TODO: use src and dst as array indices.  */
-    if (src == soc_dma_port_mem && dst == soc_dma_port_mem)
-        ch->transfer_fn = transfer_mem2mem;
-    else if (src == soc_dma_port_mem && dst == soc_dma_port_fifo)
-        ch->transfer_fn = transfer_mem2fifo;
-    else if (src == soc_dma_port_fifo && dst == soc_dma_port_mem)
-        ch->transfer_fn = transfer_fifo2mem;
-    else if (src == soc_dma_port_fifo && dst == soc_dma_port_fifo)
-        ch->transfer_fn = transfer_fifo2fifo;
-    else
+    dst = soc_dma_ch_update_type(ch, 1);
+    if (dst == soc_dma_port_other) {
+        ch->update = 0;
         ch->transfer_fn = ch->dma->transfer_fn;
+        return;
+    }
 
-    ch->update = (dst != soc_dma_port_other);
+    ch->update = 1;
+    ch->transfer_fn = transfer_fn[src][dst];
 }
 
 static void soc_dma_ch_freq_update(struct dma_s *s)
-- 
2.43.0



             reply	other threads:[~2026-06-20 17:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-20 17:13 Evgeny Kolmakov [this message]
2026-06-20 20:23 ` [PATCH] hw/dma/soc_dma: Replace if-else chain with array lookup Peter Maydell
2026-06-20 20:33   ` Evgeny
2026-06-21 13:48     ` Peter Maydell

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=20260620171318.24189-1-randomjack94dev@gmail.com \
    --to=randomjack94dev@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.