[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 06/20] sdcard: Add a "validate-crc" property
From: |
Alistair Francis |
Subject: |
Re: [Qemu-devel] [PATCH 06/20] sdcard: Add a "validate-crc" property |
Date: |
Fri, 04 May 2018 23:33:14 +0000 |
On Fri, May 4, 2018 at 9:00 AM Philippe Mathieu-Daudé <address@hidden>
wrote:
> 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é <address@hidden>
Reviewed-by: Alistair Francis <address@hidden>
Alistair
> ---
> hw/sd/milkymist-memcard.c | 1 +
> hw/sd/sd.c | 12 ++++++++----
> 2 files changed, 9 insertions(+), 4 deletions(-)
> diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c
> index d8cbb7b681..04babc092f 100644
> --- a/hw/sd/milkymist-memcard.c
> +++ b/hw/sd/milkymist-memcard.c
> @@ -278,6 +278,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 be75e118c0..801ddc2cb5 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 */
> @@ -496,10 +497,12 @@ static bool sd_verify_frame48_checksum(SDFrame48
*frame)
> return crc == frame->crc;
> }
> -static int sd_req_crc_validate(SDRequest *req)
> +static bool sd_req_crc_validate(SDState *sd, SDRequest *req)
> {
> - return 0;
> - return !sd_verify_frame48_checksum(req); /* TODO */
> + if (sd->validate_crc) {
> + return sd_verify_frame48_checksum(req);
> + }
> + return true;
> }
> static void sd_update_frame48_checksum(SDFrame48 *frame)
> @@ -1685,7 +1688,7 @@ int sd_do_command(SDState *sd, SDRequest *req,
> return 0;
> }
> - if (sd_req_crc_validate(req)) {
> + if (!sd_req_crc_validate(sd, req)) {
> sd->card_status |= COM_CRC_ERROR;
> rtype = sd_illegal;
> goto send_response;
> @@ -2134,6 +2137,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
- [Qemu-devel] [PATCH 00/20] sdcard: proper implementation of CRC, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 03/20] sdcard: Rename the SDRequest as SDFrame48, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 02/20] sdcard: Extract sd_calc_frame48_crc7() from sd_req_crc_validate(), Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 01/20] sdcard: Use the ldst API, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 04/20] sdcard: Add sd_prepare_request[_with_crc](), Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 06/20] sdcard: Add a "validate-crc" property, Philippe Mathieu-Daudé, 2018/05/04
- Re: [Qemu-devel] [PATCH 06/20] sdcard: Add a "validate-crc" property,
Alistair Francis <=
- [Qemu-devel] [PATCH 05/20] sdcard: Use the sd_prepare_request*() functions, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 07/20] sdcard: Constify sd_crc*()'s message argument, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 08/20] sdcard: Fix sd_crc*() style, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 09/20] sdcard: Expose sd_crc*() functions for QTest use, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 10/20] sdcard: Expose sd_prepare_request*() functions for QTest use, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 11/20] sdcard: Add test_sd_request_frame_crc7() qtest (request command CRC7), Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 12/20] sdcard: Let sd_frame48_crc7_calc() work on response frames, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 14/20] sdcard: Add test_sd_response_frame48_crc7 qtest (command response CRC7), Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 13/20] sdcard: Expose sd_prepare_frame48() for QTest use, Philippe Mathieu-Daudé, 2018/05/04