summary refs log tree commit diff stats
path: root/hw/sd/sd.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2021-08-04 11:40:27 +0100
committerPeter Maydell <peter.maydell@linaro.org>2021-08-04 11:40:27 +0100
commit700d82c9bc6c1c53d5f501fc2d099d28da0cef7a (patch)
tree9fcfde1d62d5228c09b6ae48f7f8da0d2ee620c9 /hw/sd/sd.c
parentef6607edf005dc5e52f60e7e1beea49bf2d48a00 (diff)
parent4ac0b72bae85cf94ae0e5153b9c2c288c71667d4 (diff)
downloadfocaccia-qemu-700d82c9bc6c1c53d5f501fc2d099d28da0cef7a.tar.gz
focaccia-qemu-700d82c9bc6c1c53d5f501fc2d099d28da0cef7a.zip
Merge remote-tracking branch 'remotes/philmd/tags/sdmmc-20210803' into staging
SD/MMC patches queue

- sdcard: Fix assertion accessing out-of-range addresses
  with SEND_WRITE_PROT (CMD30)

# gpg: Signature made Tue 03 Aug 2021 18:38:03 BST
# gpg:                using RSA key FAABE75E12917221DCFD6BB2E3E32C2CDEADC0DE
# gpg: Good signature from "Philippe Mathieu-Daudé (F4BUG) <f4bug@amsat.org>" [full]
# Primary key fingerprint: FAAB E75E 1291 7221 DCFD  6BB2 E3E3 2C2C DEAD C0DE

* remotes/philmd/tags/sdmmc-20210803:
  hw/sd/sdcard: Fix assertion accessing out-of-range addresses with CMD30
  hw/sd/sdcard: Document out-of-range addresses for SEND_WRITE_PROT

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/sd/sd.c')
-rw-r--r--hw/sd/sd.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 1f964e022b..bb5dbff68c 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -821,8 +821,15 @@ static uint32_t sd_wpbits(SDState *sd, uint64_t addr)
     wpnum = sd_addr_to_wpnum(addr);
 
     for (i = 0; i < 32; i++, wpnum++, addr += WPGROUP_SIZE) {
+        if (addr >= sd->size) {
+            /*
+             * If the addresses of the last groups are outside the valid range,
+             * then the corresponding write protection bits shall be set to 0.
+             */
+            continue;
+        }
         assert(wpnum < sd->wpgrps_size);
-        if (addr < sd->size && test_bit(wpnum, sd->wp_groups)) {
+        if (test_bit(wpnum, sd->wp_groups)) {
             ret |= (1 << i);
         }
     }