From nobody Tue Oct 28 12:33:09 2025 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 1515014979263389.0142094419921; Wed, 3 Jan 2018 13:29:39 -0800 (PST) Received: from localhost ([::1]:37635 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWqbS-0005mc-8p for importer@patchew.org; Wed, 03 Jan 2018 16:29:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51373) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWqX3-00021a-LX for qemu-devel@nongnu.org; Wed, 03 Jan 2018 16:25:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWqX2-0007ef-JG for qemu-devel@nongnu.org; Wed, 03 Jan 2018 16:25:05 -0500 Received: from mail-qt0-x241.google.com ([2607:f8b0:400d:c0d::241]:45970) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eWqX2-0007eN-Eq for qemu-devel@nongnu.org; Wed, 03 Jan 2018 16:25:04 -0500 Received: by mail-qt0-x241.google.com with SMTP id g10so3771707qtj.12 for ; Wed, 03 Jan 2018 13:25:04 -0800 (PST) Received: from x1.lan ([138.117.48.219]) by smtp.gmail.com with ESMTPSA id a19sm1104402qtj.74.2018.01.03.13.24.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jan 2018 13:25:03 -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=MB4HT3siDS/4h8YDboVhtxaMEGU58HzutDMDzup43PM=; b=pmNpTyI06iPSeLWhrDnHuc6NesrCRKVOAeATnj8XcovbSJirQ9WMm++10j3XViUyf/ srf8cf8a3oTGbM0kxGBRZ+9744XGSTCbNmvCYDJu5SMevCdxAfrV/+IKcYlLJOEQmEyU oPj6FJYmHtHxi2+ps6HQMEndkMdlDZh31SKi9OnC8f0p6D+yKqtGhxmx8czAoN5zJNJz FVxz39Obnisvj91JfLplxKUWEvO8wvL0tKldA3jxyHFlXzKdEHuI0ZTEeaSoW9aH6Ygl TLKIDkIa1h6fsuJfB3BCpLoWmgyr96JInmvUjogl8FFUiI7jWS4IPz+1jWW+/f+fI95J xskA== 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=MB4HT3siDS/4h8YDboVhtxaMEGU58HzutDMDzup43PM=; b=ZIbihGwyR4b4S7GaXlIEmbmYWaoYmiVhwmyhyCklOO75tQMJtO6S+Ht+JbM4ovbujx g9pAbWMzeE1cOixl31q8DVRVf41yh6V5oedluwhFRR7dN/b4cJ/CzSG2y+AkxTQt0kNi UkVDA9XaMtinrYLfyzODuwV40rcN3lXWDfIqzyMqfWSSRSjEUS1sKn5LytxmcIA5f89a /SLZEb9Ui3xx/0UVVfNjU3NGPK/Kp6X5sCt8m4OLviU05HLOebDEqEEiESIB09b2CS5c C7e9Z57ZvoCR/ZgaPqJX+xmTw2GJpXK0YSjJhTwXm4A90wBXrk9w9mkYfnZkYNTdL1o1 cXcg== X-Gm-Message-State: AKGB3mIszjEulDDkM/NoAbPYTbhJseAg4jpNJCnGocR3kIpbwc3WLtC/ xVYamxMV6qF1xRV2CWUCqRQ= X-Google-Smtp-Source: ACJfBosY7I63rpF0Rbob09UcnkALBRcwnaY7QQkPy8C6gNWxfzMiy5xyAOifJOUOHM385neTM9DzDQ== X-Received: by 10.200.51.20 with SMTP id t20mr3751735qta.150.1515014703948; Wed, 03 Jan 2018 13:25:03 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Alistair Francis , Peter Maydell , Igor Mitsyanko , Andrew Baumann , Olbrich , Andrzej Zaborowski Date: Wed, 3 Jan 2018 18:24:15 -0300 Message-Id: <20180103212436.15762-5-f4bug@amsat.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180103212436.15762-1-f4bug@amsat.org> References: <20180103212436.15762-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 v2 04/25] sdcard: define SDCARD_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, Paul Brook , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= 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 f0eaac4d42..489d13681d 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -56,6 +56,8 @@ do { fprintf(stderr, "SD: " fmt , ## __VA_ARGS__); } whil= e (0) #define OCR_POWER_UP 0x80000000 #define OCR_POWER_DELAY_NS 500000 /* 0.5ms */ =20 +#define SDCARD_CMD_MAX 64 + typedef enum { sd_r0 =3D 0, /* no response */ sd_r1, /* normal response command */ @@ -176,18 +178,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[SDCARD_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[SDCARD_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, @@ -787,8 +792,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, /* 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 @@ -1495,8 +1500,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, @@ -1515,6 +1520,12 @@ int sd_do_command(SDState *sd, SDRequest *req, goto send_response; } =20 + if (req->cmd >=3D SDCARD_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