Skip to contentSkip to conversation

hw/i2c/aspeed_i2c.c: Add a check for dma_read

PATCH In review Nabih Estefan 4 participants 7 messages Jan 20 – Feb 6 Arm/Aspeed machine support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/i2c/aspeed_i2c.c: Add a check for dma_read

If aspeed_i2c_dma_read fails in aspeed_i2c_bus_send currently, we get stuck in an infinite retry loop. Add a check for the return value of aspeed_i2c_dma_read that will break us out of said loop.

---
 hw/i2c/aspeed_i2c.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/i2c/aspeed_i2c.c +5 -1
index 1b8ac561c3..3de72db652 100644
@@ -272,7 +272,11 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus)
         }
         while (bus->regs[reg_dma_len]) {
             uint8_t data;
-            aspeed_i2c_dma_read(bus, &data);
+            ret = aspeed_i2c_dma_read(bus, &data);
+            /* Check that we were able to read the DMA */
+            if (ret) {
+                break;
+            }
             trace_aspeed_i2c_bus_send("DMA", bus->regs[reg_dma_len],
                                       bus->regs[reg_dma_len], data);
             ret = i2c_send(bus->bus, data);
Signature · 1 line
2.52.0.457.g6b5491de43-goog
#1 lore raw
Quoted 5 lines · Nabih Estefan

If aspeed_i2c_dma_read fails in aspeed_i2c_bus_send currently, we get stuck in an infinite retry loop. Add a check for the return value of aspeed_i2c_dma_read that will break us out of said loop.

Fixes 545d6bef7097 ("aspeed/i2c: Add support for DMA transfers")
Quoted 21 lines
---
  hw/i2c/aspeed_i2c.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
hw/i2c/aspeed_i2c.c +5 -1
index 1b8ac561c3..3de72db652 100644
@@ -272,7 +272,11 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus)
          }
          while (bus->regs[reg_dma_len]) {
              uint8_t data;
-            aspeed_i2c_dma_read(bus, &data);
+            ret = aspeed_i2c_dma_read(bus, &data);
+            /* Check that we were able to read the DMA */
+            if (ret) {
+                break;
+            }
              trace_aspeed_i2c_bus_send("DMA", bus->regs[reg_dma_len],
                                        bus->regs[reg_dma_len], data);
              ret = i2c_send(bus->bus, data);
#2 lore raw
In reply to Nabih Estefan

Hi Nabih,

Quoted 29 lines

Subject: [PATCH] hw/i2c/aspeed_i2c.c: Add a check for dma_read

If aspeed_i2c_dma_read fails in aspeed_i2c_bus_send currently, we get stuck in an infinite retry loop. Add a check for the return value of aspeed_i2c_dma_read that will break us out of said loop.

---
 hw/i2c/aspeed_i2c.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/i2c/aspeed_i2c.c index renamed from hw/i2c/aspeed_i2c.c +0 -0

1b8ac561c3..3de72db652 100644

hw/i2c/aspeed_i2c.c +5 -1
@@ -272,7 +272,11 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus)
         }
         while (bus->regs[reg_dma_len]) {
             uint8_t data;
-            aspeed_i2c_dma_read(bus, &data);
+            ret = aspeed_i2c_dma_read(bus, &data);
+            /* Check that we were able to read the DMA */
+            if (ret) {
+                break;
+            }
             trace_aspeed_i2c_bus_send("DMA", bus->regs[reg_dma_len],
                                       bus->regs[reg_dma_len],
 data);
             ret = i2c_send(bus->bus, data);
Quoted 2 lines

--
2.52.0.457.g6b5491de43-goog

Reviewed-by Jamin Lin <[email protected]>

Thanks,
Jamin

Reviewed-by on v1 1/1
#3 lore raw
In reply to Nabih Estefan
Quoted 3 lines · Nabih Estefan

If aspeed_i2c_dma_read fails in aspeed_i2c_bus_send currently, we get stuck in an infinite retry loop. Add a check for the return value of aspeed_i2c_dma_read that will break us out of said loop.

Have you ever encountered this kind of problem ?

Quoted 12 lines
---
  hw/i2c/aspeed_i2c.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
hw/i2c/aspeed_i2c.c +0 -0
index 1b8ac561c3..3de72db652 100644
@@ -272,7 +272,11 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus)
          }
          while (bus->regs[reg_dma_len]) {

hw/i2c/aspeed_i2c.c static int aspeed_i2c_bus_send(AspeedI2CBus *bus) · line 282

Quoted 10 lines
hw/i2c/aspeed_i2c.c +5 -1
              uint8_t data;
-            aspeed_i2c_dma_read(bus, &data);
+            ret = aspeed_i2c_dma_read(bus, &data);
+            /* Check that we were able to read the DMA */
+            if (ret) {
+                break;
+            }
              trace_aspeed_i2c_bus_send("DMA", bus->regs[reg_dma_len],
                                        bus->regs[reg_dma_len], data);
              ret = i2c_send(bus->bus, data);

Thanks,

C.

#4 lore raw
Quoted 8 lines · Cédric Le Goater
Quoted 3 lines · Nabih Estefan

If aspeed_i2c_dma_read fails in aspeed_i2c_bus_send currently, we get stuck in an infinite retry loop. Add a check for the return value of aspeed_i2c_dma_read that will break us out of said loop.

Have you ever encountered this kind of problem ?

I did when testing the AST1700. In one of the patchsets we had the DRAM memory initialized but not the address space (v5 has this fixed) but it took me a while to figure out what was happening because instead of failing a i2cdump or i2cget command, it would just hang. Presumably it can only happen on misconfigured or failing devices that have some address space issue, but since aspeed_i2c_dma returns an error if its fails I figured checking it had no real downside.

- Nabih

Quoted 31 lines
Quoted 13 lines
---
  hw/i2c/aspeed_i2c.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
hw/i2c/aspeed_i2c.c +0 -0
index 1b8ac561c3..3de72db652 100644
@@ -272,7 +272,11 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus)
          }
          while (bus->regs[reg_dma_len]) {

hw/i2c/aspeed_i2c.c static int aspeed_i2c_bus_send(AspeedI2CBus *bus) · line 282

Quoted 10 lines
hw/i2c/aspeed_i2c.c +5 -1
              uint8_t data;
-            aspeed_i2c_dma_read(bus, &data);
+            ret = aspeed_i2c_dma_read(bus, &data);
+            /* Check that we were able to read the DMA */
+            if (ret) {
+                break;
+            }
              trace_aspeed_i2c_bus_send("DMA", bus->regs[reg_dma_len],
                                        bus->regs[reg_dma_len], data);
              ret = i2c_send(bus->bus, data);

Thanks,

C.

#5 lore raw
In reply to Nabih Estefan
Quoted 5 lines · Nabih Estefan

If aspeed_i2c_dma_read fails in aspeed_i2c_bus_send currently, we get stuck in an infinite retry loop. Add a check for the return value of aspeed_i2c_dma_read that will break us out of said loop.

This looks like a qemu-stable material.

Please let me know if it isn't.

Thanks,

/mjt

Quoted 21 lines
---
  hw/i2c/aspeed_i2c.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
hw/i2c/aspeed_i2c.c +5 -1
index 1b8ac561c3..3de72db652 100644
@@ -272,7 +272,11 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus)
          }
          while (bus->regs[reg_dma_len]) {
              uint8_t data;
-            aspeed_i2c_dma_read(bus, &data);
+            ret = aspeed_i2c_dma_read(bus, &data);
+            /* Check that we were able to read the DMA */
+            if (ret) {
+                break;
+            }
              trace_aspeed_i2c_bus_send("DMA", bus->regs[reg_dma_len],
                                        bus->regs[reg_dma_len], data);
              ret = i2c_send(bus->bus, data);
#6 lore raw
Quoted 8 lines · Michael Tokarev
Quoted 5 lines · Nabih Estefan

If aspeed_i2c_dma_read fails in aspeed_i2c_bus_send currently, we get stuck in an infinite retry loop. Add a check for the return value of aspeed_i2c_dma_read that will break us out of said loop.

This looks like a qemu-stable material.

yes.

Thanks,

C.

Quoted 29 lines

Please let me know if it isn't.

Thanks,

/mjt

Quoted 21 lines

---
  hw/i2c/aspeed_i2c.c | 6 +++++-

  1 file changed, 5 insertions(+), 1 deletion(-)
hw/i2c/aspeed_i2c.c +5 -1
index 1b8ac561c3..3de72db652 100644
@@ -272,7 +272,11 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus)
           }
           while (bus->regs[reg_dma_len]) {
               uint8_t data;
-            aspeed_i2c_dma_read(bus, &data);
+            ret = aspeed_i2c_dma_read(bus, &data);
+            /* Check that we were able to read the DMA */
+            if (ret) {
+                break;
+            }
               trace_aspeed_i2c_bus_send("DMA", bus->regs[reg_dma_len],
                                         bus->regs[reg_dma_len], data);
               ret = i2c_send(bus->bus, data);