From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: Peter Maydell <peter.maydell@linaro.org>,
"Edgar E . Iglesias" <edgar.iglesias@xilinx.com>
Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Alistair Francis" <alistair@alistair23.me>,
"Michael Walle" <michael@walle.cc>
Subject: [Qemu-devel] [PATCH v2 13/14] sdcard: Add a "validate-crc" property
Date: Wed, 9 May 2018 00:46:57 -0300 [thread overview]
Message-ID: <20180509034658.26455-14-f4bug@amsat.org> (raw)
In-Reply-To: <20180509034658.26455-1-f4bug@amsat.org>
Since not all modelled controllers use the CRC verification (which is
somehow expensive), let the controller have a configurable property
to enable verification.
So far only the Milkymist controller uses it.
This silent the Coverity warning:
"Code block is unreachable because of the syntactic structure of the code (CWE-561)"
and fixes the following issue:
- CID1005332 (hw/sd/sd.c::sd_req_crc_validate) Structurally dead code
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/sd/milkymist-memcard.c | 1 +
hw/sd/sd.c | 10 +++++++---
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c
index 94bb1ffc6f..f7b6d3b140 100644
--- a/hw/sd/milkymist-memcard.c
+++ b/hw/sd/milkymist-memcard.c
@@ -273,6 +273,7 @@ static void milkymist_memcard_realize(DeviceState *dev, Error **errp)
blk = dinfo ? blk_by_legacy_dinfo(dinfo) : NULL;
carddev = qdev_create(&s->sdbus.qbus, TYPE_SD_CARD);
qdev_prop_set_drive(carddev, "drive", blk, &err);
+ object_property_set_bool(OBJECT(carddev), true, "validate-crc", &err);
object_property_set_bool(OBJECT(carddev), true, "realized", &err);
if (err) {
error_setg(errp, "failed to init SD card: %s", error_get_pretty(err));
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index aaf3a6806a..0170eb832b 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -93,6 +93,7 @@ struct SDState {
/* Configurable properties */
BlockBackend *blk;
bool spi;
+ bool validate_crc;
uint32_t mode; /* current card mode, one of SDCardModes */
int32_t state; /* current card state, one of SDCardStates */
@@ -467,10 +468,12 @@ static void sd_set_sdstatus(SDState *sd)
memset(sd->sd_status, 0, 64);
}
-static bool sd_req_crc_is_valid(const void *buffer)
+static bool sd_req_crc_is_valid(SDState *sd, const void *request)
{
+ if (sd->validate_crc) {
+ return sd_frame48_verify_checksum(request);
+ }
return true;
- return sd_frame48_verify_checksum(buffer); /* TODO */
}
static void sd_response_r1_make(SDState *sd, uint8_t *response)
@@ -1631,7 +1634,7 @@ int sd_do_command(SDState *sd, const uint8_t *request,
cmd = request[0];
arg = ldl_be_p(&request[1]);
- if (!sd_req_crc_is_valid(request)) {
+ if (!sd_req_crc_is_valid(sd, request)) {
sd->card_status |= COM_CRC_ERROR;
rtype = sd_illegal;
goto send_response;
@@ -2079,6 +2082,7 @@ static Property sd_properties[] = {
* board to ensure that ssi transfers only occur when the chip select
* is asserted. */
DEFINE_PROP_BOOL("spi", SDState, spi, false),
+ DEFINE_PROP_BOOL("validate-crc", SDState, validate_crc, false),
DEFINE_PROP_END_OF_LIST()
};
--
2.17.0
next prev parent reply other threads:[~2018-05-09 3:47 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-09 3:46 [Qemu-devel] [PATCH v2 00/14] sdcard: Proper implementation of CRC7 Philippe Mathieu-Daudé
2018-05-09 3:46 ` [Qemu-devel] [PATCH v2 01/14] sdcard: Use the ldst API Philippe Mathieu-Daudé
2018-06-28 17:13 ` Peter Maydell
2018-05-09 3:46 ` [Qemu-devel] [PATCH v2 02/14] sdcard: Constify sd_crc*()'s message argument Philippe Mathieu-Daudé
2018-05-09 17:58 ` Alistair Francis
2018-05-09 3:46 ` [Qemu-devel] [PATCH v2 03/14] sdcard: Fix sd_crc*() style Philippe Mathieu-Daudé
2018-05-09 3:46 ` [Qemu-devel] [PATCH v2 04/14] sdcard: Extract sd_frame48/136_calc_checksum() Philippe Mathieu-Daudé
2018-05-09 18:00 ` Alistair Francis
2018-05-09 19:15 ` Philippe Mathieu-Daudé
2018-05-09 23:04 ` Alistair Francis
2018-05-10 0:16 ` Philippe Mathieu-Daudé
2018-05-10 17:41 ` Alistair Francis
2018-05-09 3:46 ` [Qemu-devel] [PATCH v2 05/14] sdcard: Move sd_crc7() and calc_checksum() out for qtesting Philippe Mathieu-Daudé
2018-05-09 3:46 ` [Qemu-devel] [PATCH v2 06/14] sdcard: Add test_sd_verify_cksum_frame136() Philippe Mathieu-Daudé
2018-05-09 3:46 ` [Qemu-devel] [PATCH v2 07/14] sdcard: Invert the sd_req_crc_is_valid() logic Philippe Mathieu-Daudé
2018-05-09 18:02 ` Alistair Francis
2018-05-09 3:46 ` [Qemu-devel] [PATCH v2 08/14] sdcard: Extract sd_frame48_verify_checksum() out for qtesting Philippe Mathieu-Daudé
2018-05-10 0:02 ` Alistair Francis
2018-05-09 3:46 ` [Qemu-devel] [PATCH v2 09/14] sdcard: Add sd_frame136_verify_checksum() Philippe Mathieu-Daudé
2018-05-09 3:46 ` [Qemu-devel] [PATCH v2 10/14] sdcard: Remove the SDRequest argument from internal functions Philippe Mathieu-Daudé
2018-05-09 3:46 ` [Qemu-devel] [PATCH v2 11/14] sdcard: Add sd_frame48_init(), replace SDRequest by a raw buffer Philippe Mathieu-Daudé
2018-05-09 3:46 ` [Qemu-devel] [PATCH v2 12/14] sdcard: Add tests to validate the 7-bit CRC checksum of 48-bit SD frame Philippe Mathieu-Daudé
2018-05-09 3:46 ` Philippe Mathieu-Daudé [this message]
2018-05-21 12:59 ` [Qemu-devel] [PATCH v2 13/14] sdcard: Add a "validate-crc" property Michael Walle
2018-05-09 3:46 ` [Qemu-devel] [RFC PATCH v2 14/14] hw/sd/ssi-sd: Enable CRC validation Philippe Mathieu-Daudé
2018-05-09 23:06 ` Alistair Francis
2018-05-10 15:18 ` [Qemu-devel] [PATCH v2 00/14] sdcard: Proper implementation of CRC7 Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180509034658.26455-14-f4bug@amsat.org \
--to=f4bug@amsat.org \
--cc=alistair@alistair23.me \
--cc=edgar.iglesias@xilinx.com \
--cc=michael@walle.cc \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).