]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
hw/sd/ssi-sd: Return noise (dummy byte) when no card connected
authorPhilippe Mathieu-Daudé <philmd@linaro.org>
Fri, 8 Aug 2025 12:57:44 +0000 (14:57 +0200)
committerPhilippe Mathieu-Daudé <philmd@linaro.org>
Tue, 12 Aug 2025 16:52:12 +0000 (18:52 +0200)
Commit 1585ab9f1ba ("hw/sd/sdcard: Fill SPI response bits in card
code") exposed a bug in the SPI adapter: if no SD card is plugged,
we are returning "there is a card with an error". This is wrong,
we shouldn't return any particular packet response, but the noise
shifted on the MISO line. Return the dummy byte, otherwise we get:

  qemu-system-riscv64: ../hw/sd/ssi-sd.c:160: ssi_sd_transfer: Assertion `s->arglen > 0' failed.

Reported-by: Guenter Roeck <linux@roeck-us.net>
Fixes: 775616c3ae8 ("Partial SD card SPI mode support")
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Gustavo Romero <gustavo.romero@linaro.org>
Tested-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20250812140415.70153-2-philmd@linaro.org>

hw/sd/ssi-sd.c

index 594dead19eea18ab95e16205478a3c6893da22b1..3aacbd0387153dc95839f5898f4c2a115740a868 100644 (file)
@@ -89,6 +89,10 @@ static uint32_t ssi_sd_transfer(SSIPeripheral *dev, uint32_t val)
     SDRequest request;
     uint8_t longresp[5];
 
+    if (!sdbus_get_inserted(&s->sdbus)) {
+        return SSI_DUMMY;
+    }
+
     /*
      * Special case: allow CMD12 (STOP TRANSMISSION) while reading data.
      *