From nobody Sat May 11 08:53:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.128.49 as permitted sender) client-ip=209.85.128.49; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-f49.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.49 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1627496258; cv=none; d=zohomail.com; s=zohoarc; b=YA4rhE8zSKvdci5tkT6eu7wqOifkFAIisNKti1h2T7h/LOrg3Y2Dq5g/cJfdA9oJ+XZPQVS1FEsGfXHbMAVVA+/3Fk5WRtVltnks5wIwD7o+/uuK3z1l1ShYsOlHPvRUecxfs2it8CwfiOJRT20Xv64SRpR3z13e7PPTS6y4ErY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1627496258; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rpJr73sHcD06uaEUnanxw7L+gRVTgFYkDb7sUWR7li8=; b=S2coGvBsq2AmUHiwPQtbVZDbIHxXVisAYiqJEDmQJp71jjfSuqUMNBrWUHgvHfFgd7tKHl6Q2Y6d5cqtAM40nt/jBg1QWvn0A7+Nr40fniGJbup3XvFFkvuGP46jIUBqI7x1Wvefw0c5BrRmndpeRuVBNY0xEaA1UloJHemxqF4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.49 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by mx.zohomail.com with SMTPS id 1627496258437218.14454589026968; Wed, 28 Jul 2021 11:17:38 -0700 (PDT) Received: by mail-wm1-f49.google.com with SMTP id f14-20020a05600c154eb02902519e4abe10so5001084wmg.4 for ; Wed, 28 Jul 2021 11:17:37 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (122.red-83-42-66.dynamicip.rima-tde.net. [83.42.66.122]) by smtp.gmail.com with ESMTPSA id k17sm605872wrw.53.2021.07.28.11.17.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 11:17:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rpJr73sHcD06uaEUnanxw7L+gRVTgFYkDb7sUWR7li8=; b=IZlCmLCtZtTVWI/l7DJ2ATbnmmDJMYSGAJZVba0a8irrPX6zOYMF3OYFWkslxvJzh8 2LIO6Tira7B594R6Sxr7011d+0l9qwhlviexow7ZsHzSynWeVzWjPNRgGyhU70P8/906 8ly4XwuJi+T83lwtNrnwBSM72iB1xfCcFhr27HkRUbTA1OAJ6e1N7DoHfMNfJwkwV/km itGFvxAe2LTzEXRSXbi9AOiRODoCfTONeifdcOW+ZYpL/bFy23MJ2bM0nt5nZqS+WfdJ XredUAhkyw3ldWYfhjKx0qnllJ7tKgJoTNp1SYmxOHAC411C8i/o8z06kMEBJRG5/CX1 BleA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=rpJr73sHcD06uaEUnanxw7L+gRVTgFYkDb7sUWR7li8=; b=eG5C20e5KgP732NuhY1az3JcEq7PaVFx11gyCuTbYP/s9fbv1gtb/q87A8UTMlj5Uy 4JL8tZdr5g5TXUcJRYVGs1jk8S15odzcgjZRS+H4C9WXyc+1aQuagQhlBp9JBJDCXX/L 5jAmefrklIrvzQehNOTYyDo3W1uMOYAl7pdY0MuHQp/ZqDQFIJXIb3/a//MXTXT3dPTK VTlQvBiE4f4XsdJiEIeLLt89lm5i5v34m2t6NdTiCUcSh6eZzVwEOMjB8vS4gUZfl15o dmhj0u+PPZZVy+qsvjKCzgFhbMkb6DeF2DLBgx7dyXap/jj60WHodHX6vIix8ozXhFnK IBlw== X-Gm-Message-State: AOAM531y/3/vJC3aVf7UbIdqs+D64wBvJaPaZjY9GIFdBfVMWrQkVG9y SCbTv3swsU7p8Dc6aXstWqg= X-Google-Smtp-Source: ABdhPJzkJ8R6AgWyZK+P3LG7TxygmbudutwlPUmcX9tFnKkwLuz2XHJPqCjxxXv8x1bg1JyF+PYMRQ== X-Received: by 2002:a1c:7314:: with SMTP id d20mr10670921wmb.156.1627496256645; Wed, 28 Jul 2021 11:17:36 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bin Meng , qemu-block@nongnu.org, qemu-arm@nongnu.org, Alexander Bulekov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH-for-6.1 1/3] hw/sd/sdcard: Document out-of-range addresses for SEND_WRITE_PROT Date: Wed, 28 Jul 2021 20:17:26 +0200 Message-Id: <20210728181728.2012952-2-f4bug@amsat.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210728181728.2012952-1-f4bug@amsat.org> References: <20210728181728.2012952-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1627496260284100001 Per the 'Physical Layer Simplified Specification Version 3.01', Table 4-22: 'Block Oriented Write Protection Commands' SEND_WRITE_PROT (CMD30) If the card provides write protection features, this command asks the card to send the status of the write protection bits [1]. [1] 32 write protection bits (representing 32 write protect groups starting at the specified address) [...] The last (least significant) bit of the protection bits corresponds to the first addressed group. If the addresses of the last groups are outside the valid range, then the corresponding write protection bits shall be set to 0. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alexander Bulekov --- hw/sd/sd.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 1f964e022b1..707dcc12a14 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -822,7 +822,14 @@ static uint32_t sd_wpbits(SDState *sd, uint64_t addr) =20 for (i =3D 0; i < 32; i++, wpnum++, addr +=3D WPGROUP_SIZE) { assert(wpnum < sd->wpgrps_size); - if (addr < sd->size && test_bit(wpnum, sd->wp_groups)) { + if (addr >=3D sd->size) { + /* + * If the addresses of the last groups are outside the valid r= ange, + * then the corresponding write protection bits shall be set t= o 0. + */ + continue; + } + if (test_bit(wpnum, sd->wp_groups)) { ret |=3D (1 << i); } } --=20 2.31.1 From nobody Sat May 11 08:53:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.46 as permitted sender) client-ip=209.85.221.46; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f46.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.46 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1627496263; cv=none; d=zohomail.com; s=zohoarc; b=k04LPKz+8DPffntI6fHBC0fERVckni4q2E73AFxoVxF8hTIZZaofd2cmiu9Pvosch8z5ykB5xsbRy3WtcgzKFoUNWhB2d5z21/H1DVcYkmKqnteg/yFbmTtX6i22+fu7+53th5UKCA/A0/0ioZhiFT4gHuwhy8Giwb4BO21Kdl4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1627496263; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YwYKVHNgecu5jiIKoXnoWtjk/FNw2rOw7861LGYxMNs=; b=dSFHmAdYEcb6R3FSfTBT8vjxMacMEFY9BN9YXLTymdpyv5R/WwPo1KLs8x+6zSbcupDOQ/gQMBpgaMz0gJ5Sid/nDnG6TxKPY6Ryvk5VYsSCm0WDXoQMmXpahik2wrKnx3zpnFWeHPSw8CmCXYQqE2F1P89WL5l6i//cgGXosYE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.46 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by mx.zohomail.com with SMTPS id 1627496263549982.349379337772; Wed, 28 Jul 2021 11:17:43 -0700 (PDT) Received: by mail-wr1-f46.google.com with SMTP id j2so3646390wrx.9 for ; Wed, 28 Jul 2021 11:17:42 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (122.red-83-42-66.dynamicip.rima-tde.net. [83.42.66.122]) by smtp.gmail.com with ESMTPSA id v5sm614199wrd.74.2021.07.28.11.17.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 11:17:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YwYKVHNgecu5jiIKoXnoWtjk/FNw2rOw7861LGYxMNs=; b=fy9J5xznGE0VLXw+HWBexvcNxEB0SuThh+YUPyuqh/X+TgrMej8Tz3M63H4ONwFB1u JYzurTtXN3lCT+/MPRvpbNjGnKccz3TbFZIpCkfDow4OM9goCMQxAoHvLXRZk7ZTH1bH LcVpTjbsBY6oxeAoq6BBWa0pjlKZR7Nn1TWQj4qiO+wqJL/UXmJZLr1sE/h/DdDgaXgG 0k2QersmTjfrYvfCDrqNPZDH1iozBuPQj+0m9YXl1bCV+za12sd9+4CaxcEb7d61aR+z tzQpnnddtwNQh5W/627bZiViwgyrwzJD4IvIPh0GEO4UEp3zzgq0SmpUPxPQhKYsaBK+ hvMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=YwYKVHNgecu5jiIKoXnoWtjk/FNw2rOw7861LGYxMNs=; b=ges5jUhRQhzFja+DUCzRAk5yLtVJHkeiNcevCIatSToTIeODO1sV0+kCk5wg3tdJUI 8ZmNEpuGd9ZN+pOWw9+RqpXq5HhNttQigi5C6CzsKQ4+ob3G7rKddsN6ArFo39m8UQ3c ibSphSSOoE3J5/+FN2v1SNODW2IAHshXo8SeTz/bng7k1Hq7NuXI1UpNFpKpPGVX23xV tlNHKqrZVg9EJbLG8HG4lMxtQXo1qMdsscQ+7G4bjAfX1ISbjK65PB4d4aIKrbaCbzm7 6cl7QI0KylaEk8jdNwNVB5a5jjwIOpFTVMyI1bYQ947Z1VwcbwBM0D4gBrwiAcdT5jt9 dlMw== X-Gm-Message-State: AOAM532Tg5TXcewzgp1L/B9/dMddPmTEtITjQD7yp0lVCzeafSBZHtJc Rqgh0HNKb2ojKUnLPecyFRQ= X-Google-Smtp-Source: ABdhPJyZYmkpkyVUCqBdcQVKEoSji5VcnZDFm4a411qC3uQzfpzGwoJj7JuoSLL2P0xKIbUluKhIlg== X-Received: by 2002:adf:f1c6:: with SMTP id z6mr674996wro.207.1627496261720; Wed, 28 Jul 2021 11:17:41 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bin Meng , qemu-block@nongnu.org, qemu-arm@nongnu.org, Alexander Bulekov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-stable@nongnu.org Subject: [PATCH-for-6.1 2/3] hw/sd/sdcard: Fix assertion accessing out-of-range addresses with CMD30 Date: Wed, 28 Jul 2021 20:17:27 +0200 Message-Id: <20210728181728.2012952-3-f4bug@amsat.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210728181728.2012952-1-f4bug@amsat.org> References: <20210728181728.2012952-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1627496264808100001 OSS-Fuzz found sending illegal addresses when querying the write protection bits triggers the assertion added in commit 84816fb63e5 ("hw/sd/sdcard: Assert if accessing an illegal group"): qemu-fuzz-i386-target-generic-fuzz-sdhci-v3: ../hw/sd/sd.c:824: uint32_t = sd_wpbits(SDState *, uint64_t): Assertion `wpnum < sd->wpgrps_size' failed. #3 0x7f62a8b22c91 in __assert_fail #4 0x5569adcec405 in sd_wpbits hw/sd/sd.c:824:9 #5 0x5569adce5f6d in sd_normal_command hw/sd/sd.c:1389:38 #6 0x5569adce3870 in sd_do_command hw/sd/sd.c:1737:17 #7 0x5569adcf1566 in sdbus_do_command hw/sd/core.c:100:16 #8 0x5569adcfc192 in sdhci_send_command hw/sd/sdhci.c:337:12 #9 0x5569adcfa3a3 in sdhci_write hw/sd/sdhci.c:1186:9 #10 0x5569adfb3447 in memory_region_write_accessor softmmu/memory.c:492:5 It is legal for the CMD30 to query for out-of-range addresses. Such invalid addresses are simply ignored in the response (write protection bits set to 0). Note, we had an off-by-one in the wpgrps_size check since commit a1bb27b1e98. Since we have a total of 'wpgrps_size' bits, the latest valid group bit is 'wpgrps_size - 1'. Since we now check the group bit is in range, remove the assertion. Include the qtest reproducer provided by Alexander Bulekov: $ make check-qtest-i386 ... Running test qtest-i386/fuzz-sdcard-test qemu-system-i386: ../hw/sd/sd.c:824: sd_wpbits: Assertion `wpnum < sd->wp= grps_size' failed. Cc: qemu-stable@nongnu.org Reported-by: OSS-Fuzz (Issue 29225) Resolves: https://gitlab.com/qemu-project/qemu/-/issues/495 Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/sd/sd.c | 4 ++-- tests/qtest/fuzz-sdcard-test.c | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 707dcc12a14..273af75c1be 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -820,8 +820,8 @@ static uint32_t sd_wpbits(SDState *sd, uint64_t addr) =20 wpnum =3D sd_addr_to_wpnum(addr); =20 - for (i =3D 0; i < 32; i++, wpnum++, addr +=3D WPGROUP_SIZE) { - assert(wpnum < sd->wpgrps_size); + for (i =3D 0; i < 32 && wpnum < sd->wpgrps_size - 1; + i++, wpnum++, addr +=3D WPGROUP_SIZE) { if (addr >=3D sd->size) { /* * If the addresses of the last groups are outside the valid r= ange, diff --git a/tests/qtest/fuzz-sdcard-test.c b/tests/qtest/fuzz-sdcard-test.c index 96602eac7e5..ae14305344a 100644 --- a/tests/qtest/fuzz-sdcard-test.c +++ b/tests/qtest/fuzz-sdcard-test.c @@ -52,6 +52,41 @@ static void oss_fuzz_29225(void) qtest_quit(s); } =20 +/* + * https://gitlab.com/qemu-project/qemu/-/issues/495 + * Used to trigger: + * Assertion `wpnum < sd->wpgrps_size' failed. + */ +static void oss_fuzz_36217(void) +{ + QTestState *s; + + s =3D qtest_init(" -display none -m 32 -nodefaults -nographic" + " -device sdhci-pci,sd-spec-version=3D3 " + "-device sd-card,drive=3Dd0 " + "-drive if=3Dnone,index=3D0,file=3Dnull-co://,format=3D= raw,id=3Dd0"); + + qtest_outl(s, 0xcf8, 0x80001010); + qtest_outl(s, 0xcfc, 0xe0000000); + qtest_outl(s, 0xcf8, 0x80001004); + qtest_outw(s, 0xcfc, 0x02); + qtest_bufwrite(s, 0xe000002c, "\x05", 0x1); + qtest_bufwrite(s, 0xe000000f, "\x37", 0x1); + qtest_bufwrite(s, 0xe000000a, "\x01", 0x1); + qtest_bufwrite(s, 0xe000000f, "\x29", 0x1); + qtest_bufwrite(s, 0xe000000f, "\x02", 0x1); + qtest_bufwrite(s, 0xe000000f, "\x03", 0x1); + qtest_bufwrite(s, 0xe0000005, "\x01", 0x1); + qtest_bufwrite(s, 0xe000000f, "\x06", 0x1); + qtest_bufwrite(s, 0xe000000c, "\x05", 0x1); + qtest_bufwrite(s, 0xe000000e, "\x20", 0x1); + qtest_bufwrite(s, 0xe000000f, "\x08", 0x1); + qtest_bufwrite(s, 0xe000000b, "\x3d", 0x1); + qtest_bufwrite(s, 0xe000000f, "\x1e", 0x1); + + qtest_quit(s); +} + int main(int argc, char **argv) { const char *arch =3D qtest_get_arch(); @@ -60,6 +95,7 @@ int main(int argc, char **argv) =20 if (strcmp(arch, "i386") =3D=3D 0) { qtest_add_func("fuzz/sdcard/oss_fuzz_29225", oss_fuzz_29225); + qtest_add_func("fuzz/sdcard/oss_fuzz_36217", oss_fuzz_36217); } =20 return g_test_run(); --=20 2.31.1 From nobody Sat May 11 08:53:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.50 as permitted sender) client-ip=209.85.221.50; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f50.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.50 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1627496269; cv=none; d=zohomail.com; s=zohoarc; b=Ddmr0Nh/UzkFLDpcK1nLm28f1I5F8Mtw7BymzYDQPctneeCpNSFY6WLX6vhMDg7FlH5mVbnrMvpzmWtKtrlAEUYMSZRjBWnqidQL65qe+fsAbO2enNInQAeiLgjV0RMVJxtYBAM+hOQmBHkSjWEgxkeUx6gaRAzzjRRAifq0DkM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1627496269; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5i0w3FlnQcOgLRKzBoRNyImyhfiPU5ZjX8yICvUvUkE=; b=KmPbNSrCFPy/wVERpWJag/B1Xmd+ko91q7mcBV5vaHFKXhQsIhSiowhlm/Mpvl/jR0QLIo7JyguPxbSzewgynyXrQGNTxWjvryFFTLI8Q2uXGHYF8in1ErdudtODvkhI1WaC1Wf9hcpOqF08m+OoOrqhB+IxDSZNOwnaLvY/ImE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.50 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by mx.zohomail.com with SMTPS id 1627496269570359.2973924878273; Wed, 28 Jul 2021 11:17:49 -0700 (PDT) Received: by mail-wr1-f50.google.com with SMTP id c16so3640080wrp.13 for ; Wed, 28 Jul 2021 11:17:49 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (122.red-83-42-66.dynamicip.rima-tde.net. [83.42.66.122]) by smtp.gmail.com with ESMTPSA id h9sm627332wrw.38.2021.07.28.11.17.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 11:17:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5i0w3FlnQcOgLRKzBoRNyImyhfiPU5ZjX8yICvUvUkE=; b=ZaeBtspzj6iIdvkpcIjr63oqg+TVdJfpdhoFCRWh65JrCVKct5oRb4r1qmqDSRjvqG sjPIq1sALHWcMAnOA3T/Mz0IzJJe3GI48mPUINNBat3jhDH6mdsFYcecNHNNp3aBDBt4 PTepUbsRoQ5kYLA+4uWfo5aC3scYFgNQVtDbqwzN5fcX2sOcOclqa6uaNTD7W1CnIvZ0 mG5qOG1GES9NHRpw2pgTe004ERgkB2wv2qRIA0IzkqEFEFV9AK1xJQWjofdHU9kIwQvw Yh6II7/pmuW4+e12DiqE3b69rTJBiK8rD5wqhyAykYyT0OXYy/tDSMv9YKXTE/IiFXAh mcTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=5i0w3FlnQcOgLRKzBoRNyImyhfiPU5ZjX8yICvUvUkE=; b=NpwZTvRpsPPjCyHty2Gz667kQfHEPG/bEWlzCY1Om2RsfxDs21cuKZJA8YJJMXUhdY NyB3mdCkrnQFKWve2Ph+Ckc8gtwROd2ptmFo7ACJ+5litmvE/HK5VcmazXy3kElDMYAw AXpTTCSUP7+J8NjGPNJYg1p9oZag/EjiiwqCYL/a6KvrcHN7J+PqZzjHeKw5j76cGe42 Ar+veIbYEk4cOqB4bTDCudWnh9algL2XzffwmVAgLYDP3tUlsfLvy+csmbYLdFuCoQ7+ vi5CUlz1UHoWDAa7v5Yc9eF2AloeD9WRSIxt0t3SvN8sT6QaL4Ha9opbMULkULLXz51Y Q6JQ== X-Gm-Message-State: AOAM532dUw0MAuIwReBWNauRkVNmeq3BqGc1BQsEGBwRg6x1t2dUrvgf bNIgOr4sBnX4FZyuWZLUicA= X-Google-Smtp-Source: ABdhPJz0L7nY2b/HeOeChHkTBSJYUQY2gip0IMgqN0kUpKH5P1FmXySOR3XM2L+KOzyJ7P7/fPRkqw== X-Received: by 2002:adf:d086:: with SMTP id y6mr684960wrh.247.1627496267637; Wed, 28 Jul 2021 11:17:47 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bin Meng , qemu-block@nongnu.org, qemu-arm@nongnu.org, Alexander Bulekov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH-for-6.2 3/3] hw/sd/sdcard: Rename Write Protect Group variables Date: Wed, 28 Jul 2021 20:17:28 +0200 Message-Id: <20210728181728.2012952-4-f4bug@amsat.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210728181728.2012952-1-f4bug@amsat.org> References: <20210728181728.2012952-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1627496271865100001 'wp_groups' holds a bitmap, rename it as 'wp_group_bmap'. 'wpgrps_size' is the bitmap size (in bits), rename it as 'wp_group_bits'. Patch created mechanically using: $ sed -i -e s/wp_groups/wp_group_bmap/ \ -e s/wpgrps_size/wp_group_bits/ hw/sd/sd.c Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alexander Bulekov --- hw/sd/sd.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 273af75c1be..75dcd3f7f65 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -116,8 +116,8 @@ struct SDState { int32_t state; /* current card state, one of SDCardStates */ uint32_t vhs; bool wp_switch; - unsigned long *wp_groups; - int32_t wpgrps_size; + unsigned long *wp_group_bmap; + int32_t wp_group_bits; uint64_t size; uint32_t blk_len; uint32_t multi_blk_cnt; @@ -567,10 +567,10 @@ static void sd_reset(DeviceState *dev) sd_set_cardstatus(sd); sd_set_sdstatus(sd); =20 - g_free(sd->wp_groups); + g_free(sd->wp_group_bmap); sd->wp_switch =3D sd->blk ? !blk_is_writable(sd->blk) : false; - sd->wpgrps_size =3D sect; - sd->wp_groups =3D bitmap_new(sd->wpgrps_size); + sd->wp_group_bits =3D sect; + sd->wp_group_bmap =3D bitmap_new(sd->wp_group_bits); memset(sd->function_group, 0, sizeof(sd->function_group)); sd->erase_start =3D INVALID_ADDRESS; sd->erase_end =3D INVALID_ADDRESS; @@ -673,7 +673,7 @@ static const VMStateDescription sd_vmstate =3D { VMSTATE_UINT32(card_status, SDState), VMSTATE_PARTIAL_BUFFER(sd_status, SDState, 1), VMSTATE_UINT32(vhs, SDState), - VMSTATE_BITMAP(wp_groups, SDState, 0, wpgrps_size), + VMSTATE_BITMAP(wp_group_bmap, SDState, 0, wp_group_bits), VMSTATE_UINT32(blk_len, SDState), VMSTATE_UINT32(multi_blk_cnt, SDState), VMSTATE_UINT32(erase_start, SDState), @@ -803,8 +803,8 @@ static void sd_erase(SDState *sd) if (sdsc) { /* Only SDSC cards support write protect groups */ wpnum =3D sd_addr_to_wpnum(erase_addr); - assert(wpnum < sd->wpgrps_size); - if (test_bit(wpnum, sd->wp_groups)) { + assert(wpnum < sd->wp_group_bits); + if (test_bit(wpnum, sd->wp_group_bmap)) { sd->card_status |=3D WP_ERASE_SKIP; continue; } @@ -820,7 +820,7 @@ static uint32_t sd_wpbits(SDState *sd, uint64_t addr) =20 wpnum =3D sd_addr_to_wpnum(addr); =20 - for (i =3D 0; i < 32 && wpnum < sd->wpgrps_size - 1; + for (i =3D 0; i < 32 && wpnum < sd->wp_group_bits - 1; i++, wpnum++, addr +=3D WPGROUP_SIZE) { if (addr >=3D sd->size) { /* @@ -829,7 +829,7 @@ static uint32_t sd_wpbits(SDState *sd, uint64_t addr) */ continue; } - if (test_bit(wpnum, sd->wp_groups)) { + if (test_bit(wpnum, sd->wp_group_bmap)) { ret |=3D (1 << i); } } @@ -869,7 +869,7 @@ static void sd_function_switch(SDState *sd, uint32_t ar= g) =20 static inline bool sd_wp_addr(SDState *sd, uint64_t addr) { - return test_bit(sd_addr_to_wpnum(addr), sd->wp_groups); + return test_bit(sd_addr_to_wpnum(addr), sd->wp_group_bmap); } =20 static void sd_lock_command(SDState *sd) @@ -897,7 +897,7 @@ static void sd_lock_command(SDState *sd) sd->card_status |=3D LOCK_UNLOCK_FAILED; return; } - bitmap_zero(sd->wp_groups, sd->wpgrps_size); + bitmap_zero(sd->wp_group_bmap, sd->wp_group_bits); sd->csd[14] &=3D ~0x10; sd->card_status &=3D ~CARD_IS_LOCKED; sd->pwd_len =3D 0; @@ -1348,7 +1348,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) } =20 sd->state =3D sd_programming_state; - set_bit(sd_addr_to_wpnum(addr), sd->wp_groups); + set_bit(sd_addr_to_wpnum(addr), sd->wp_group_bmap); /* Bzzzzzzztt .... Operation complete. */ sd->state =3D sd_transfer_state; return sd_r1b; @@ -1370,7 +1370,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) } =20 sd->state =3D sd_programming_state; - clear_bit(sd_addr_to_wpnum(addr), sd->wp_groups); + clear_bit(sd_addr_to_wpnum(addr), sd->wp_group_bmap); /* Bzzzzzzztt .... Operation complete. */ sd->state =3D sd_transfer_state; return sd_r1b; --=20 2.31.1