diff mbox series

[PATCH-for-7.2,2/2] hw/sd/sdhci: Factor common Present State bits in sdhci_data_transfer()

Message ID 20221107221236.47841-3-philmd@linaro.org
State New
Headers show
Series hw/sd/sdhci: Do not set Buf Wr Ena before writing block (CVE-2022-3872) | expand

Commit Message

Philippe Mathieu-Daudé Nov. 7, 2022, 10:12 p.m. UTC
When we do a non-DMA transfer, we have to set the 'DAT Line Active'
and 'Command Inhibit (DAT)' bits in the 'Present State' register.

Factor that common code to ease code review.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/sd/sdhci.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index f230e7475f..e9bb3576f4 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -909,6 +909,7 @@  static void sdhci_data_transfer(void *opaque)
     SDHCIState *s = (SDHCIState *)opaque;
 
     if (s->trnmod & SDHC_TRNS_DMA) {
+        /* DMA Data transfer: DMA functionality available and enabled */
         switch (SDHC_DMA_TYPE(s->hostctl1)) {
         case SDHC_CTRL_SDMA:
             if ((s->blkcnt == 1) || !(s->trnmod & SDHC_TRNS_MULTI)) {
@@ -948,13 +949,13 @@  static void sdhci_data_transfer(void *opaque)
             break;
         }
     } else {
+        /* Non-DMA data transfer: DMA functionality not available or disabled */
+        s->prnsts |= SDHC_DAT_LINE_ACTIVE | SDHC_DATA_INHIBIT;
         if ((s->trnmod & SDHC_TRNS_READ) && sdbus_data_ready(&s->sdbus)) {
-            s->prnsts |= SDHC_DOING_READ | SDHC_DATA_INHIBIT |
-                    SDHC_DAT_LINE_ACTIVE;
+            s->prnsts |= SDHC_DOING_READ;
             sdhci_read_block_from_card(s);
         } else {
-            s->prnsts |= SDHC_DOING_WRITE | SDHC_DAT_LINE_ACTIVE |
-                                           SDHC_DATA_INHIBIT;
+            s->prnsts |= SDHC_DOING_WRITE;
             sdhci_write_block_to_card(s);
         }
     }