From nobody Tue Feb 10 16:22:17 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516677996698662.5286983770504; Mon, 22 Jan 2018 19:26:36 -0800 (PST) Received: from localhost ([::1]:59041 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edpEH-00078z-37 for importer@patchew.org; Mon, 22 Jan 2018 22:26:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35478) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edp9w-0003eX-VJ for qemu-devel@nongnu.org; Mon, 22 Jan 2018 22:22:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edp9v-0000kZ-VP for qemu-devel@nongnu.org; Mon, 22 Jan 2018 22:22:04 -0500 Received: from mail-qt0-x241.google.com ([2607:f8b0:400d:c0d::241]:38049) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edp9v-0000kC-QV for qemu-devel@nongnu.org; Mon, 22 Jan 2018 22:22:03 -0500 Received: by mail-qt0-x241.google.com with SMTP id z10so26434053qti.5 for ; Mon, 22 Jan 2018 19:22:03 -0800 (PST) Received: from x1.lan ([138.117.48.219]) by smtp.gmail.com with ESMTPSA id x207sm5545567qka.91.2018.01.22.19.22.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Jan 2018 19:22:02 -0800 (PST) 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=MbqfjqxK3drjK/Ic04s78QrnYiKM+r10WgvDgy6+92k=; b=EHcNHnmDWktFFUbLTNcVpypRWq+2Xu1JqVh7iMYtPP9wHrAJADiDDjycGj5Xlr0KDh i2AzumvoSdh1+4WOJcQ0ZOLrxUR7fTwpNh1voq/GobQ+376ddaE/Dzy1CKebcZttZYFp 5mIpiktpJW+1VHdY2+hN8FvB55zGkIP051njqaDkwft3+jw/kmF1r+dms1m6iFQhgvOT rCCghy82Xz2wnyC0E7ch8bHsUPXCYkfd64m0EroUwr6asCWlT0yz23ANmEyI4QnUWuV8 Nbca8FlrldqeRjRi7fRcsE9F7ieDmMuAQJy+7Ef0IaUEXQo56kqCTW5DTDSO5zpzeMgr 6IyA== 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=MbqfjqxK3drjK/Ic04s78QrnYiKM+r10WgvDgy6+92k=; b=iGzKsuXg515DIqzMmUWlqiN6vIgQVp/asI+Ds3E11cTRfqBBaeY+fSWEIcn1Zf7r5a V19aqUiwaKsn79cVb04DP9cxtc6J7KV/A8XzujQJcWutRd274kzdZx9r3prJ5vsj6F9U a1COS2ctxvA3S1IyfZJoc+exy07D8W+2PD/fsFBZzfKSeTMobmFtDXEvyPhZDrk+PkGv kziqM4THaJ9s4r8jflNKYLwmt8ZgZCEV4x21s2pPaY8YDUMzq8qBONw7qHEXpDr7FwUw 04In0HwwCvwrjgNIwo9bxk6lnxyQmh9A8ZSPw/bumJKOScLHukTjst0rvfNV7kOX8MO0 DCHw== X-Gm-Message-State: AKwxytf4et7vxy2jTPG8uDFOWVBGhjZf2Rb4YiU0dAfryT2SyJ264mFz h6adrwC/MYAZITZWMYgssU4= X-Google-Smtp-Source: AH8x227i3TaO6ZtqQhF8Ud2SkQiP3afH7yAEFIkDW3Vl/xVRRDSDIzazVfBWevO7+Mztt4/DFazJaQ== X-Received: by 10.55.25.37 with SMTP id k37mr1451720qkh.221.1516677723392; Mon, 22 Jan 2018 19:22:03 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Alistair Francis , Peter Maydell , Igor Mitsyanko Date: Tue, 23 Jan 2018 00:21:30 -0300 Message-Id: <20180123032135.28863-8-f4bug@amsat.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180123032135.28863-1-f4bug@amsat.org> References: <20180123032135.28863-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::241 Subject: [Qemu-devel] [PATCH v3 07/12] sdcard: define SDMMC_CMD_MAX instead of using the magic '64' X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Edgar E . Iglesias" , Prasad J Pandit , Peter Crosthwaite , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis --- hw/sd/sd.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 27c08aa894..7b1cbc0a2e 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -126,6 +126,8 @@ struct SDState { bool cmd_line; }; =20 +#define SDMMC_CMD_MAX 64 + static const char *sd_state_name(enum SDCardStates state) { static const char *state_name[] =3D { @@ -213,18 +215,21 @@ static void sd_set_mode(SDState *sd) } } =20 -static const sd_cmd_type_t sd_cmd_type[64] =3D { +static const sd_cmd_type_t sd_cmd_type[SDMMC_CMD_MAX] =3D { sd_bc, sd_none, sd_bcr, sd_bcr, sd_none, sd_none, sd_none, sd_ac, sd_bcr, sd_ac, sd_ac, sd_adtc, sd_ac, sd_ac, sd_none, sd_ac, + /* 16 */ sd_ac, sd_adtc, sd_adtc, sd_none, sd_none, sd_none, sd_none, sd_none, sd_adtc, sd_adtc, sd_adtc, sd_adtc, sd_ac, sd_ac, sd_adtc, sd_none, + /* 32 */ sd_ac, sd_ac, sd_none, sd_none, sd_none, sd_none, sd_ac, sd_none, sd_none, sd_none, sd_bc, sd_none, sd_none, sd_none, sd_none, sd_none, + /* 48 */ sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_ac, sd_adtc, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, }; =20 -static const int sd_cmd_class[64] =3D { +static const int sd_cmd_class[SDMMC_CMD_MAX] =3D { 0, 0, 0, 0, 0, 9, 10, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 6, 6, 6, 6, 5, 5, 10, 10, 10, 10, 5, 9, 9, 9, 7, 7, 7, 7, 7, 7, @@ -829,8 +834,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDR= equest req) /* Not interpreting this as an app command */ sd->card_status &=3D ~APP_CMD; =20 - if (sd_cmd_type[req.cmd & 0x3F] =3D=3D sd_ac - || sd_cmd_type[req.cmd & 0x3F] =3D=3D sd_adtc) { + if (sd_cmd_type[req.cmd] =3D=3D sd_ac + || sd_cmd_type[req.cmd] =3D=3D sd_adtc) { rca =3D req.arg >> 16; } =20 @@ -1542,8 +1547,8 @@ static int cmd_valid_while_locked(SDState *sd, SDRequ= est *req) if (req->cmd =3D=3D 16 || req->cmd =3D=3D 55) { return 1; } - return sd_cmd_class[req->cmd & 0x3F] =3D=3D 0 - || sd_cmd_class[req->cmd & 0x3F] =3D=3D 7; + return sd_cmd_class[req->cmd] =3D=3D 0 + || sd_cmd_class[req->cmd] =3D=3D 7; } =20 int sd_do_command(SDState *sd, SDRequest *req, @@ -1562,6 +1567,12 @@ int sd_do_command(SDState *sd, SDRequest *req, goto send_response; } =20 + if (req->cmd >=3D SDMMC_CMD_MAX) { + qemu_log_mask(LOG_GUEST_ERROR, "SD: incorrect command 0x%02x\n", + req->cmd); + req->cmd &=3D 0x3f; + } + if (sd->card_status & CARD_IS_LOCKED) { if (!cmd_valid_while_locked(sd, req)) { sd->card_status |=3D ILLEGAL_COMMAND; --=20 2.15.1