diff mbox series

[PATCH-for-9.1?,v2,1/4] hw/sd/sdhci: Reduce variables scope in sdhci_do_adma()

Message ID 20240731212501.44385-2-philmd@linaro.org
State New
Headers show
Series hw/sd/sdhci: Check ADMA descriptors can be accessed | expand

Commit Message

Philippe Mathieu-Daudé July 31, 2024, 9:24 p.m. UTC
All variables are only used within the for loop.
Declare them within it. In particular this resets
'dscr' on each iteration.

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

Patch

diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index 66b9364e9e..773f2b284b 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -751,20 +751,19 @@  static void get_adma_description(SDHCIState *s, ADMADescr *dscr)
 
 static void sdhci_do_adma(SDHCIState *s)
 {
-    unsigned int begin, length;
-    const uint16_t block_size = s->blksize & BLOCK_SIZE_MASK;
-    const MemTxAttrs attrs = { .memory = true };
-    ADMADescr dscr = {};
-    MemTxResult res;
-    int i;
-
     if (s->trnmod & SDHC_TRNS_BLK_CNT_EN && !s->blkcnt) {
         /* Stop Multiple Transfer */
         sdhci_end_transfer(s);
         return;
     }
 
-    for (i = 0; i < SDHC_ADMA_DESCS_PER_DELAY; ++i) {
+    for (int i = 0; i < SDHC_ADMA_DESCS_PER_DELAY; ++i) {
+        unsigned int begin, length;
+        const uint16_t block_size = s->blksize & BLOCK_SIZE_MASK;
+        const MemTxAttrs attrs = { .memory = true };
+        ADMADescr dscr = { };
+        MemTxResult res;
+
         s->admaerr &= ~SDHC_ADMAERR_LENGTH_MISMATCH;
 
         get_adma_description(s, &dscr);