From c239084f5b2b13e74716071a5e029329a52e643a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Tue, 25 Jun 2024 04:48:12 +0200 Subject: [PATCH] hw/sd/sdcard: Restrict SWITCH_FUNCTION to sd_transfer_state (CMD6) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit SWITCH_FUNCTION is only allowed in TRANSFER state (See 4.8 "Card State Transition Table). Fixes: a1bb27b1e9 ("Initial SD card emulation") Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater Message-Id: <20240628070216.92609-13-philmd@linaro.org> --- hw/sd/sd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 396185f240..b5d002e6d7 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1204,6 +1204,10 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) if (sd->mode != sd_data_transfer_mode) { return sd_invalid_mode_for_cmd(sd, req); } + if (sd->state != sd_transfer_state) { + return sd_invalid_state_for_cmd(sd, req); + } + sd_function_switch(sd, req.arg); sd->state = sd_sendingdata_state; sd->data_start = 0; -- 2.11.4.GIT