From patchwork Tue Jun 30 13:38:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 279026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0968FC433E0 for ; Tue, 30 Jun 2020 13:40:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C9731206EB for ; Tue, 30 Jun 2020 13:40:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LRQ4E4B9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C9731206EB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:56522 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqGVE-00031U-3P for qemu-devel@archiver.kernel.org; Tue, 30 Jun 2020 09:40:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34874) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqGTn-0000xF-CP; Tue, 30 Jun 2020 09:39:19 -0400 Received: from mail-ed1-x543.google.com ([2a00:1450:4864:20::543]:36171) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jqGTl-0006Hg-TT; Tue, 30 Jun 2020 09:39:19 -0400 Received: by mail-ed1-x543.google.com with SMTP id dg28so16232499edb.3; Tue, 30 Jun 2020 06:39:17 -0700 (PDT) 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=MjRNdoa0rZpF8KkV/ND0ssqMkJTZ9vSTBVaUds1+aIY=; b=LRQ4E4B9mhCntLThCwvhzuRdnRTQT6wb556Yxds/8mtYujDx/epvCiTfHqW4Zrto+e k+/VMLot5f/ujVjCSPek348c3ufqgFqOah+fbScfmJzVGHKDtUQ74npCkptfL7/nSHrv OK/YQGv6R75/hIYdAqWoBFFsSjRfuX/ohzrXibmLF01D3bY2ESkMKhGujynYfK93E1Vw Uubzunr3w6Az5RQmpE3UpKSq8SNFKdZv34koVOtB/2Q2GY00SzsJgcNPrs0wjJja3Wzl lziI6KVZS8ifdRSmYA/kmcJQ3XbwOXtdUbe7JZLaBr88XmdgA/AD77H5CkE+tjE8yhW0 KrgA== 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=MjRNdoa0rZpF8KkV/ND0ssqMkJTZ9vSTBVaUds1+aIY=; b=hArqCgWRNyP1LOLVKrD4/u/sjqjyAVQ3PIShRcvXlePHdXk36z+EFfDrHwRwv7SQ6H vR6tNzIRlEuxx6krHgIUUXCaSJW208Gfu3R74HSuAQFaNDpaTdvw/4zHTOK2k/GEiZ8T Dlbjgg257+4M0ICep8ucpeeFbbdkqNqBZgVwRwXa7CiChFauxe1j18M3pEXH09L7d8x4 Oc8614ywXVJRn1Xd4UzZ/8Pr0k1DRdd4FMc3MDKsSGcRrfFuCyFKRAhWF9QFOjjgIPRn 2bT/OxeeYXsyoErzxcfpUQ1KP5rAZQbPKVXdNZqJ1UVL075mFD50sQ9bDGeeYbXxfcYn +udw== X-Gm-Message-State: AOAM533wFIsqDm/l+9AHxp7U1Ehf/ePfX/bKkta1KbF3E4QH6YI+mj4l r3o+z58NGZpjdcBQXiFGH+bXvkd5qIc= X-Google-Smtp-Source: ABdhPJxGtwbRjK9kmKgl1UtrZcORC5uF60RHxNz/zCaFQtqrwM7JCM2lzjyJjoiHO1AxnR7wlLVsZg== X-Received: by 2002:a05:6402:30b2:: with SMTP id df18mr23218583edb.229.1593524356073; Tue, 30 Jun 2020 06:39:16 -0700 (PDT) Received: from x1w.redhat.com (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id p18sm2099172ejm.55.2020.06.30.06.39.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 06:39:15 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v7 02/17] hw/sd/sdcard: Update coding style to make checkpatch.pl happy Date: Tue, 30 Jun 2020 15:38:56 +0200 Message-Id: <20200630133912.9428-3-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200630133912.9428-1-f4bug@amsat.org> References: <20200630133912.9428-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::543; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ed1-x543.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?b?YXVkw6k=?= , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Philippe Mathieu-Daudé To make the next commit easier to review, clean this code first. Reviewed-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 97a9d32964..cac8d7d828 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1170,8 +1170,9 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) sd->data_start = addr; sd->data_offset = 0; - if (sd->data_start + sd->blk_len > sd->size) + if (sd->data_start + sd->blk_len > sd->size) { sd->card_status |= ADDRESS_ERROR; + } return sd_r1; default: @@ -1186,8 +1187,9 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) sd->data_start = addr; sd->data_offset = 0; - if (sd->data_start + sd->blk_len > sd->size) + if (sd->data_start + sd->blk_len > sd->size) { sd->card_status |= ADDRESS_ERROR; + } return sd_r1; default: @@ -1232,12 +1234,15 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) sd->data_offset = 0; sd->blk_written = 0; - if (sd->data_start + sd->blk_len > sd->size) + if (sd->data_start + sd->blk_len > sd->size) { sd->card_status |= ADDRESS_ERROR; - if (sd_wp_addr(sd, sd->data_start)) + } + if (sd_wp_addr(sd, sd->data_start)) { sd->card_status |= WP_VIOLATION; - if (sd->csd[14] & 0x30) + } + if (sd->csd[14] & 0x30) { sd->card_status |= WP_VIOLATION; + } return sd_r1; default: @@ -1256,12 +1261,15 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) sd->data_offset = 0; sd->blk_written = 0; - if (sd->data_start + sd->blk_len > sd->size) + if (sd->data_start + sd->blk_len > sd->size) { sd->card_status |= ADDRESS_ERROR; - if (sd_wp_addr(sd, sd->data_start)) + } + if (sd_wp_addr(sd, sd->data_start)) { sd->card_status |= WP_VIOLATION; - if (sd->csd[14] & 0x30) + } + if (sd->csd[14] & 0x30) { sd->card_status |= WP_VIOLATION; + } return sd_r1; default: From patchwork Tue Jun 30 13:38:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 279024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86513C433DF for ; Tue, 30 Jun 2020 13:43:11 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 526AF20675 for ; Tue, 30 Jun 2020 13:43:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G5tK4TLj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 526AF20675 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:37184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqGXW-0007HZ-Iz for qemu-devel@archiver.kernel.org; Tue, 30 Jun 2020 09:43:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34898) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqGTp-00010m-IN; Tue, 30 Jun 2020 09:39:21 -0400 Received: from mail-ed1-x542.google.com ([2a00:1450:4864:20::542]:45646) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jqGTo-0006IM-2S; Tue, 30 Jun 2020 09:39:21 -0400 Received: by mail-ed1-x542.google.com with SMTP id d16so9594107edz.12; Tue, 30 Jun 2020 06:39:19 -0700 (PDT) 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=i3AX6k9zJcs7ntcPjDjs5EOqKiW+/SX/Gp5bwn7hkCA=; b=G5tK4TLjUXy/6OdiMLeBcI82VCrGi2aWIt4P7LB6EG6ihgTle21nQr58Q/nNBJ3Ehg X4z0Aq5mDo0d6VC5pMxCZLYFpZxfG4XCBPoNdhUxuOS2iCsbRb+jI3Pz4Mr+VKhlC3BD 69fvSKB7OR6hUANJ1pRQJxSJg3BlmV/JxRVMtPceeTWxSBDgRNvE/PXCdzLGERi/US/5 EuFVcOR/BazQvOWm+pUsUS+TX1eRhZuyTZpvp4Pv+wi2ABj6CizK1x+bsDwAO0N7JYY5 Fxl3DKKvsehrxyG7puZ2bNRqSu4SQQKIqZGAnWIXgBay8Y/k1xsuuyX5uZDf98t8NksW OuDg== 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=i3AX6k9zJcs7ntcPjDjs5EOqKiW+/SX/Gp5bwn7hkCA=; b=CdMtmWqTZDOfFXXXLusaszDsb1Jip8Ddn8Tpgz4J25BZJaBO3KD5WvIJ/u0hCKmEdK TBpX6s4Hezkuo3wAJGBDhjflyg0s7Xy1vj9QCDA967l+AmAOQ3kD9KfIZj734/XAGqtZ ktP0anK5YLPeNSm4pBbPyc9IAL+LJbz86S/01/GuxjkiKy+9Ptze6c9Gs3oDvkaOC9ni mf5JdunsEN3/V+iuyHusU1HHq4nRDfbhMrA9RDY27jc4ViR4ERngOtbiQT5RcPawofBF 4jDu4tYRk8qGkrolc+Q3rujQ4NKydZ7AIlD80WE9FaAtKlEaItgrMIpZbdQ1+3NvfIkY TV9w== X-Gm-Message-State: AOAM531Osg7ThY5Q2UZ7W+NSCnMdO+ObGkGRix6chDCTGyWoEQfdGKUx 2ebMOWOCz+5YoSTXsZM9IgOW0zY+ycs= X-Google-Smtp-Source: ABdhPJzXNdpvEdMno8aAobnvdP0TBwsu6gwsmsxv+lwBNlmn2aKa3AwrUTBmKBGh71YQvprD7PnHkQ== X-Received: by 2002:a50:cd1a:: with SMTP id z26mr23903371edi.120.1593524358353; Tue, 30 Jun 2020 06:39:18 -0700 (PDT) Received: from x1w.redhat.com (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id p18sm2099172ejm.55.2020.06.30.06.39.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 06:39:17 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v7 04/17] hw/sd/sdcard: Use the HWBLOCK_SIZE definition Date: Tue, 30 Jun 2020 15:38:58 +0200 Message-Id: <20200630133912.9428-5-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200630133912.9428-1-f4bug@amsat.org> References: <20200630133912.9428-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::542; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ed1-x542.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?b?YXVkw6k=?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Replace the following different uses of the same value by the same HWBLOCK_SIZE definition: - 512 (magic value) - 0x200 (magic value) - 1 << HWBLOCK_SHIFT Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 4816b4a462..04451fdad2 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -81,6 +81,7 @@ enum SDCardStates { }; #define HWBLOCK_SHIFT 9 /* 512 bytes */ +#define HWBLOCK_SIZE (1 << HWBLOCK_SHIFT) #define SECTOR_SHIFT 5 /* 16 kilobytes */ #define WPGROUP_SHIFT 7 /* 2 megs */ #define CMULT_SHIFT 9 /* 512 times HWBLOCK_SIZE */ @@ -129,7 +130,7 @@ struct SDState { uint32_t blk_written; uint64_t data_start; uint32_t data_offset; - uint8_t data[512]; + uint8_t data[HWBLOCK_SIZE]; qemu_irq readonly_cb; qemu_irq inserted_cb; QEMUTimer *ocr_power_timer; @@ -410,7 +411,7 @@ static void sd_set_csd(SDState *sd, uint64_t size) ((HWBLOCK_SHIFT << 6) & 0xc0); sd->csd[14] = 0x00; /* File format group */ } else { /* SDHC */ - size /= 512 * KiB; + size /= HWBLOCK_SIZE * KiB; size -= 1; sd->csd[0] = 0x40; sd->csd[1] = 0x0e; @@ -574,7 +575,7 @@ static void sd_reset(DeviceState *dev) sd->erase_start = 0; sd->erase_end = 0; sd->size = size; - sd->blk_len = 0x200; + sd->blk_len = HWBLOCK_SIZE; sd->pwd_len = 0; sd->expecting_acmd = false; sd->dat_lines = 0xf; @@ -685,7 +686,7 @@ static const VMStateDescription sd_vmstate = { VMSTATE_UINT32(blk_written, SDState), VMSTATE_UINT64(data_start, SDState), VMSTATE_UINT32(data_offset, SDState), - VMSTATE_UINT8_ARRAY(data, SDState, 512), + VMSTATE_UINT8_ARRAY(data, SDState, HWBLOCK_SIZE), VMSTATE_UNUSED_V(1, 512), VMSTATE_BOOL(enable, SDState), VMSTATE_END_OF_LIST() @@ -754,8 +755,8 @@ static void sd_erase(SDState *sd) if (FIELD_EX32(sd->ocr, OCR, CARD_CAPACITY)) { /* High capacity memory card: erase units are 512 byte blocks */ - erase_start *= 512; - erase_end *= 512; + erase_start *= HWBLOCK_SIZE; + erase_end *= HWBLOCK_SIZE; } erase_start = sd_addr_to_wpnum(erase_start); @@ -1149,7 +1150,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 16: /* CMD16: SET_BLOCKLEN */ switch (sd->state) { case sd_transfer_state: - if (req.arg > (1 << HWBLOCK_SHIFT)) { + if (req.arg > HWBLOCK_SIZE) { sd->card_status |= BLOCK_LEN_ERROR; } else { trace_sdcard_set_blocklen(req.arg); @@ -1961,7 +1962,7 @@ uint8_t sd_read_data(SDState *sd) if (sd->card_status & (ADDRESS_ERROR | WP_VIOLATION)) return 0x00; - io_len = (sd->ocr & (1 << 30)) ? 512 : sd->blk_len; + io_len = (sd->ocr & (1 << 30)) ? HWBLOCK_SIZE : sd->blk_len; trace_sdcard_read_data(sd->proto_name, sd_acmd_name(sd->current_cmd), From patchwork Tue Jun 30 13:38:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 279023 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A011C433E0 for ; Tue, 30 Jun 2020 13:44:03 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2A0B920675 for ; Tue, 30 Jun 2020 13:44:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GIs8+CuD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2A0B920675 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:39926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqGYM-0000J6-Bd for qemu-devel@archiver.kernel.org; Tue, 30 Jun 2020 09:44:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34932) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqGTr-00015i-FM; Tue, 30 Jun 2020 09:39:23 -0400 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]:35458) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jqGTp-0006Ig-IG; Tue, 30 Jun 2020 09:39:23 -0400 Received: by mail-ed1-x541.google.com with SMTP id e15so16262012edr.2; Tue, 30 Jun 2020 06:39:20 -0700 (PDT) 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=0q3fvINBMewfm4ouk0ChZ+kON+bgL7uzrdyA1Uly1X8=; b=GIs8+CuD1T/pqGNj1zHsxRLmZI2rDcsOrC59ZM79eGONAOxKZXBVhT5hEX5MBEL78M zBTTdRhjkD8B45LUwtPGvXRWonQgabLIvA7MxBTBJ1Ej04Kto9AdePsXCNep4ku35mZT rIND5BKiTzQdY7im6HQhRJhgUNmRkvENrFpd7IXnB2VD0y7ssOvxdsnOwsmgedBYi+EV RVYpXwHE+QTS1h8RvmN+hacfnrf1adT2jKZ6X/IDUvInu8MAKBU4Qck3+HuqsO8SfDfk uItjfzh/Rzvh9NnEHAUokDK//pvEYfjSrl7glbDb5L4QnYLMFxIRTh/0CDegWTSO4e0c EdkA== 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=0q3fvINBMewfm4ouk0ChZ+kON+bgL7uzrdyA1Uly1X8=; b=rNgeiJG5orSB58IVR2Njk/E9NDGnuw+KF/MgceL3v2FY5jsAbZ52TEphxZcvXe/AJf Rt/wQSi+TGarK99EbwB8zIyy3Pz+PzXBwoUGcSnMN5bk9ck43XkVyFt6gfEi2KXVUPvF zqEG8PmeSJwN4kb+mTlcrvoXh9vB+4KeYuPXGVN+NThw02EaPC3UWiw3KprCKbeBxibb 1tLHxGN2h8GtZV96vtwdgeGbKAO0wG4F+7j0gW+1g900aoZwj1GOsSPDxb19yiH+Xt8W lArgkI5IZTOMkbuI2lOgdGcjzRkIRhLMV8iegJyGqq+Km2P3b59e2HLjCX1e+39yI8Uc 2RkQ== X-Gm-Message-State: AOAM531OoB8ecyYVc08BjgfJSvpvhAhi/Y9V9rDW8DEFQPFyzdJTdgAP kF7Cyb1MshwG9+27f104MCy7jiRlpCA= X-Google-Smtp-Source: ABdhPJw1SoT1uZcIHek+c6O/yVAXSslixwy/+Tb4nrodLzsaUKwo9PQvUX8wkGukQ/MKwVE6AQIDuQ== X-Received: by 2002:a05:6402:1d89:: with SMTP id dk9mr11430759edb.31.1593524359525; Tue, 30 Jun 2020 06:39:19 -0700 (PDT) Received: from x1w.redhat.com (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id p18sm2099172ejm.55.2020.06.30.06.39.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 06:39:18 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v7 05/17] hw/sd/sdcard: Do not switch to ReceivingData if address is invalid Date: Tue, 30 Jun 2020 15:38:59 +0200 Message-Id: <20200630133912.9428-6-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200630133912.9428-1-f4bug@amsat.org> References: <20200630133912.9428-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::541; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ed1-x541.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Prasad J Pandit , qemu-block@nongnu.org, =?utf-8?q?Philippe_Ma?= =?utf-8?q?thieu-Daud=C3=A9?= , Alexander Bulekov , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Only move the state machine to ReceivingData if there is no pending error. This avoids later OOB access while processing commands queued. "SD Specifications Part 1 Physical Layer Simplified Spec. v3.01" 4.3.3 Data Read Read command is rejected if BLOCK_LEN_ERROR or ADDRESS_ERROR occurred and no data transfer is performed. 4.3.4 Data Write Write command is rejected if BLOCK_LEN_ERROR or ADDRESS_ERROR occurred and no data transfer is performed. WP_VIOLATION errors are not modified: the error bit is set, we stay in receive-data state, wait for a stop command. All further data transfer is ignored. See the check on sd->card_status at the beginning of sd_read_data() and sd_write_data(). Fixes: CVE-2020-13253 Cc: Prasad J Pandit Reported-by: Alexander Bulekov Buglink: https://bugs.launchpad.net/qemu/+bug/1880822 Signed-off-by: Philippe Mathieu-Daudé --- v4: Only modify ADDRESS_ERROR, not WP_VIOLATION (pm215) --- hw/sd/sd.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 04451fdad2..7e0d684aca 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1167,13 +1167,15 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 17: /* CMD17: READ_SINGLE_BLOCK */ switch (sd->state) { case sd_transfer_state: - sd->state = sd_sendingdata_state; - sd->data_start = addr; - sd->data_offset = 0; if (sd->data_start + sd->blk_len > sd->size) { sd->card_status |= ADDRESS_ERROR; + return sd_r1; } + + sd->state = sd_sendingdata_state; + sd->data_start = addr; + sd->data_offset = 0; return sd_r1; default: @@ -1184,13 +1186,15 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 18: /* CMD18: READ_MULTIPLE_BLOCK */ switch (sd->state) { case sd_transfer_state: - sd->state = sd_sendingdata_state; - sd->data_start = addr; - sd->data_offset = 0; if (sd->data_start + sd->blk_len > sd->size) { sd->card_status |= ADDRESS_ERROR; + return sd_r1; } + + sd->state = sd_sendingdata_state; + sd->data_start = addr; + sd->data_offset = 0; return sd_r1; default: @@ -1230,14 +1234,17 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) /* Writing in SPI mode not implemented. */ if (sd->spi) break; + + if (sd->data_start + sd->blk_len > sd->size) { + sd->card_status |= ADDRESS_ERROR; + return sd_r1; + } + sd->state = sd_receivingdata_state; sd->data_start = addr; sd->data_offset = 0; sd->blk_written = 0; - if (sd->data_start + sd->blk_len > sd->size) { - sd->card_status |= ADDRESS_ERROR; - } if (sd_wp_addr(sd, sd->data_start)) { sd->card_status |= WP_VIOLATION; } @@ -1257,14 +1264,17 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) /* Writing in SPI mode not implemented. */ if (sd->spi) break; + + if (sd->data_start + sd->blk_len > sd->size) { + sd->card_status |= ADDRESS_ERROR; + return sd_r1; + } + sd->state = sd_receivingdata_state; sd->data_start = addr; sd->data_offset = 0; sd->blk_written = 0; - if (sd->data_start + sd->blk_len > sd->size) { - sd->card_status |= ADDRESS_ERROR; - } if (sd_wp_addr(sd, sd->data_start)) { sd->card_status |= WP_VIOLATION; } From patchwork Tue Jun 30 13:39:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 279025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B2F6C433E0 for ; Tue, 30 Jun 2020 13:41:24 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6BA6620675 for ; Tue, 30 Jun 2020 13:41:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Amx+bG5I" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6BA6620675 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:58628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqGVn-0003qX-MY for qemu-devel@archiver.kernel.org; Tue, 30 Jun 2020 09:41:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34968) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqGTt-00019o-9X; Tue, 30 Jun 2020 09:39:25 -0400 Received: from mail-ej1-x643.google.com ([2a00:1450:4864:20::643]:42881) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jqGTr-0006J3-Mx; Tue, 30 Jun 2020 09:39:24 -0400 Received: by mail-ej1-x643.google.com with SMTP id i14so20647699ejr.9; Tue, 30 Jun 2020 06:39:22 -0700 (PDT) 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=+lTrHlDODPJpVtiU5OSZTdaw0jvk522ED9AiYmpwBdo=; b=Amx+bG5IOb19PFGlatNgqyoTpsPxQdKJ9xNkHVrIWxuCXan9PQgwJcP7S/yzcIFUE7 VQ8x1gQzFn/de21TbiIUd26uNey+ybBOAr8dZ54UwZpJycyQal2C5XtD6Q4vDCjpuGTM pQxGg/kn6tzbKmZkFSEEAWGVvSfEcsB3S+BQ8+NOXJ114vSglrlGsFqHALxhQggh/mu5 E/aV58HghfMugC1bH5wSpX66SmgsNuUYayDPG2fCzE2lJcuhnvmJxtwjjNzTtCnh7SMR 9P2gK2M40rN8bUtumOXeOItLLkG4ycxDsnQkAY0pfGvayHpukI4yHDtrCIAcJ4fQA3C/ 8RFw== 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=+lTrHlDODPJpVtiU5OSZTdaw0jvk522ED9AiYmpwBdo=; b=hdwKk6HvknrPjLhSwwdJG3/7vlvHOdrM5WqUSSjwgc2K4BtqdeUdxIdwzenZo3uIqM c9DC3B9M9kLnCs5P2nOM9/Ic5cjTppI6E2uinD1eeDWqyb5wbpzvkSHTOii0woouSXfi cSb8LZUkYwGW7gJThxPFbqdoNZvSAgQgaJJbU1CLXPqVn6AJp2WBElLcYTBh73zHFtsx V7R8hju9LRjrT0+EOWOn666JOz8xKITyjiBPL4JdPfhoiP4tJsm7UFxkXrQmjX3R3B7L Ad+oBF/8pvPCmnOeQPGD+44+FehD4jpt+ZNbyaI4fK9MDLabawNVOppvggrp6EQmpKb3 5dQQ== X-Gm-Message-State: AOAM5333AhKNy+3kJlu3QQ0EeOLl70y4SmvAgCFWuY74Q1SyGFWPTLIw 1/0okNyXYauEQhtscI9nN3rEiOjDYOE= X-Google-Smtp-Source: ABdhPJxAF7cCd1uIHgOnnfaFMLvVJ/8HUZI2UXvzdwvUsq21TylrJsTovPjBPhA8f7CKv0ex0G9TBQ== X-Received: by 2002:a17:906:7ac9:: with SMTP id k9mr17639635ejo.489.1593524361714; Tue, 30 Jun 2020 06:39:21 -0700 (PDT) Received: from x1w.redhat.com (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id p18sm2099172ejm.55.2020.06.30.06.39.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 06:39:21 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v7 07/17] hw/sd/sdcard: Move sd->size initialization Date: Tue, 30 Jun 2020 15:39:01 +0200 Message-Id: <20200630133912.9428-8-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200630133912.9428-1-f4bug@amsat.org> References: <20200630133912.9428-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::643; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ej1-x643.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?b?YXVkw6k=?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Move sd->size initialization earlier to make the following patches easier to review. Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 871c30a67f..078b0e81ee 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -558,12 +558,13 @@ static void sd_reset(DeviceState *dev) sect = sd_addr_to_wpnum(size) + 1; + sd->size = size; sd->state = sd_idle_state; sd->rca = 0x0000; sd_set_ocr(sd); sd_set_scr(sd); sd_set_cid(sd); - sd_set_csd(sd, size); + sd_set_csd(sd, sd->size); sd_set_cardstatus(sd); sd_set_sdstatus(sd); @@ -574,7 +575,6 @@ static void sd_reset(DeviceState *dev) memset(sd->function_group, 0, sizeof(sd->function_group)); sd->erase_start = 0; sd->erase_end = 0; - sd->size = size; sd->blk_len = HWBLOCK_SIZE; sd->pwd_len = 0; sd->expecting_acmd = false; From patchwork Tue Jun 30 13:39:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 279022 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24866C433E0 for ; Tue, 30 Jun 2020 13:45:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E885A20675 for ; Tue, 30 Jun 2020 13:45:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aRM854uz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E885A20675 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqGa1-0003DQ-5X for qemu-devel@archiver.kernel.org; Tue, 30 Jun 2020 09:45:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqGTx-0001Hk-F1; Tue, 30 Jun 2020 09:39:30 -0400 Received: from mail-ej1-x644.google.com ([2a00:1450:4864:20::644]:39520) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jqGTw-0006KN-1s; Tue, 30 Jun 2020 09:39:29 -0400 Received: by mail-ej1-x644.google.com with SMTP id w6so20656581ejq.6; Tue, 30 Jun 2020 06:39:27 -0700 (PDT) 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=XqwjlBbJ3fvA8pvvTo8a4BEWNTwUPbni3z+WTf5U/ws=; b=aRM854uztcoPNwlS6NAx0ri7TbvqffQaO97GKQrnriimWCRkcTe3NH40HaXWUtMeCG mXf+XEz5g6pWFvJ4A1O9KhJetp8QF43qXxZkAcp2SVu5G1IS8HFVGwYxJOXxY2ufPv7w JlGQ/HieZ+0TDoLidm0LfyC6yRdr4+Rp/6r3ldFtXqbGXDaHXonLc3C7rRdE7zOhwng5 J/qPOKORSiyFsinrbxOOVVbcV+E2xGaUNOsTJ4cyErCGrROoCVRDjrBb7wobomKeRhix FFCdLpYNl/xgQ/9GXdkZsUaBEnZVYCsdgTgfAWA5stLkeeFtDpNfniATarWgKNftISvf Rkfw== 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=XqwjlBbJ3fvA8pvvTo8a4BEWNTwUPbni3z+WTf5U/ws=; b=AkLq9g0pkQcwv6LKqXpH4LafoMJrKjS8KJiCGtt0Awko36awsnuorVqcVKIKGJkTS3 TyMiFT9Umj/fm5kCaJnY1bCreKoTzFstlVeuPbNHqUJdQhYBkbSjxV+CjOBsj6l6jhW5 myZ7LEiQ6gYcKEc3m+H99bnlF2K8as58oJtT7pev5qCBvohzA0xNhIl+WR2cTDyPPvCq Zcb0yeRKedoPZIfIfdAky5mEFGNdhgbPEn/9eL6eL38oo8Bm4xWhgamoSkyZA/oymmfh 3Y4R/DKYU1z453b1v5pGG7yqV/li7nJfkLJ7jIaQp32pm1x5QKv77bm8ZH+SylZ8+O8f GwcQ== X-Gm-Message-State: AOAM530fk7/3jYLZtzH9gbBtIm2khOgj6xXNp95MhGr1t0FUn+u6rRpm tQoRaz4eipgtHdEPMUU4Z1nPqO4/uK0= X-Google-Smtp-Source: ABdhPJz/3CAAUu9olncDoAnQzS3yXRUTiL8abT5FHzPXHxbpIz1gsIC9UQ+qvTuzJN6Jiodg2TiC/A== X-Received: by 2002:a17:907:9c6:: with SMTP id bx6mr18313287ejc.43.1593524366235; Tue, 30 Jun 2020 06:39:26 -0700 (PDT) Received: from x1w.redhat.com (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id p18sm2099172ejm.55.2020.06.30.06.39.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 06:39:25 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v7 11/17] hw/sd/sdcard: Update the SDState documentation Date: Tue, 30 Jun 2020 15:39:05 +0200 Message-Id: <20200630133912.9428-12-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200630133912.9428-1-f4bug@amsat.org> References: <20200630133912.9428-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::644; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ej1-x644.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?b?YXVkw6k=?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add more descriptive comments to keep a clear separation between static property vs runtime changeable. Suggested-by: Peter Maydell Reviewed-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 5d1b314a32..723e66bbf2 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -103,11 +103,14 @@ struct SDState { uint32_t card_status; uint8_t sd_status[64]; - /* Configurable properties */ + /* Static properties */ + uint8_t spec_version; BlockBackend *blk; bool spi; + /* Runtime changeables */ + uint32_t mode; /* current card mode, one of SDCardModes */ int32_t state; /* current card state, one of SDCardStates */ uint32_t vhs; From patchwork Tue Jun 30 13:39:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 279021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE854C433DF for ; Tue, 30 Jun 2020 13:46:11 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7F3F520675 for ; Tue, 30 Jun 2020 13:46:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="L0dm+Zqg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F3F520675 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:48594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqGaQ-0004Do-PS for qemu-devel@archiver.kernel.org; Tue, 30 Jun 2020 09:46:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqGTy-0001Hv-HS; Tue, 30 Jun 2020 09:39:30 -0400 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]:40715) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jqGTx-0006Kb-2M; Tue, 30 Jun 2020 09:39:30 -0400 Received: by mail-ed1-x541.google.com with SMTP id b15so16234116edy.7; Tue, 30 Jun 2020 06:39:28 -0700 (PDT) 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=7oWhhwBqOvLGS6HnYqHl1FI0efPvaFKdOE8O2MKYuLA=; b=L0dm+ZqgiTie6OqdRv2fFH6DqA8j4GmsGBHeZe2v+H0MklGV+lbtTAimlVC3HMiq4w 5MfNxG7MMXXilmRB8FQJsiB7feNbmNrrR3a++y27YKSGNksbLGmNIhBt7eMS5N+BPk69 CtjVXTf1ZP+imlarsz1MrpP0bEaSg3jdA8MrmXOxx6EErgT4DIRZv1lkgT4CHJ7zXEnk VFgPj9eEECTarvHeUNonolmo6LV/ycslhrlU4q6bP3P0FdUWj62TC9FVcT+B/FX28gkR Fm0nVizy+P3HJHmSs3QoGzxcAiTagqwgk0+9gOr9fzs9tYaGos0cGC6TtksMuvFByS4L C7Lw== 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=7oWhhwBqOvLGS6HnYqHl1FI0efPvaFKdOE8O2MKYuLA=; b=qVTteFwfZSNVJ2eGA2PRSTAYqkelZwijDQbWlho8tI1ygvVL+0BR7fRzXcVunJDfPq +41ZJv2ZbVssHp8iMwT3yWpBa12jFiZ2Yur+Rebe5AVKWsIk69D9zum2VsKNjQxpBhvo RLoSp/O07PGeDNvTMeQMHfrQiBqazvg9RLOKBeZ9e6FevaPKk4v13Kxa7jkX5X5Px8RG ZEEvHIkejnqISdi6p6cqWmD1QFBahZZ/ZeYcVDp/Cke7mNITF7W8EhybGUsTyjGEPKoK uwJ+mGQCvbhs2N9l+19MiEDR36DCZWV/CCENEA/HDjgGNcE6DYyanpdfozalGJM+kQUS 4u3g== X-Gm-Message-State: AOAM5328+oIyaVauxXHrpo7kDWwW1y/YivxssIuGALKX/EU/DFkW3605 T3zlD/L0+aGVdeID27Z1Cc6pBDc3q1Y= X-Google-Smtp-Source: ABdhPJwZ7/Rz1K65mRo7TyScy1OmrO0JiOvkn+aoPtLYMsS18Y2iZNioQkqB8INEQ3oksb0VmaMPIw== X-Received: by 2002:a50:fd84:: with SMTP id o4mr4229758edt.117.1593524367335; Tue, 30 Jun 2020 06:39:27 -0700 (PDT) Received: from x1w.redhat.com (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id p18sm2099172ejm.55.2020.06.30.06.39.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 06:39:26 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v7 12/17] hw/sd/sdcard: Simplify cmd_valid_while_locked() Date: Tue, 30 Jun 2020 15:39:06 +0200 Message-Id: <20200630133912.9428-13-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200630133912.9428-1-f4bug@amsat.org> References: <20200630133912.9428-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::541; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ed1-x541.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?b?YXVkw6k=?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" cmd_valid_while_locked() only needs to read SDRequest->cmd, pass it directly and make it const. Reviewed-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 723e66bbf2..2946fe3040 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1678,7 +1678,7 @@ static sd_rsp_type_t sd_app_command(SDState *sd, return sd_illegal; } -static int cmd_valid_while_locked(SDState *sd, SDRequest *req) +static int cmd_valid_while_locked(SDState *sd, const uint8_t cmd) { /* Valid commands in locked state: * basic class (0) @@ -1689,13 +1689,12 @@ static int cmd_valid_while_locked(SDState *sd, SDRequest *req) * Anything else provokes an "illegal command" response. */ if (sd->expecting_acmd) { - return req->cmd == 41 || req->cmd == 42; + return cmd == 41 || cmd == 42; } - if (req->cmd == 16 || req->cmd == 55) { + if (cmd == 16 || cmd == 55) { return 1; } - return sd_cmd_class[req->cmd] == 0 - || sd_cmd_class[req->cmd] == 7; + return sd_cmd_class[cmd] == 0 || sd_cmd_class[cmd] == 7; } int sd_do_command(SDState *sd, SDRequest *req, @@ -1721,7 +1720,7 @@ int sd_do_command(SDState *sd, SDRequest *req, } if (sd->card_status & CARD_IS_LOCKED) { - if (!cmd_valid_while_locked(sd, req)) { + if (!cmd_valid_while_locked(sd, req->cmd)) { sd->card_status |= ILLEGAL_COMMAND; sd->expecting_acmd = false; qemu_log_mask(LOG_GUEST_ERROR, "SD: Card is locked\n"); From patchwork Tue Jun 30 13:39:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 279020 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60364C433DF for ; Tue, 30 Jun 2020 13:50:06 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2A89B206BE for ; Tue, 30 Jun 2020 13:50:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cAIOek2+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2A89B206BE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:37828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqGeD-0003G1-Bx for qemu-devel@archiver.kernel.org; Tue, 30 Jun 2020 09:50:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35090) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqGTz-0001KO-SS; Tue, 30 Jun 2020 09:39:31 -0400 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]:41732) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jqGTy-0006Kw-7Q; Tue, 30 Jun 2020 09:39:31 -0400 Received: by mail-ed1-x544.google.com with SMTP id e22so16227400edq.8; Tue, 30 Jun 2020 06:39:29 -0700 (PDT) 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=/74ZOEVtWoI92Rhuv9NWA62JHOdD9/euQUb+Sj4+JZg=; b=cAIOek2+VUlEPq6VZObms5zcks/UNF8orPh7ODrxUf93whGbPppvaEOUNBNgIjVtwb RnJJj+a10P+abz3HB4QjiMILLCTSI24rjITO7ftpDHypTR8DOiiEcibRZZt63Ilqzcba EobA8YDO+yZG1yEm4piNn/Bbt9tvLnQxlkwuBMAE1gcDJB0zwm3+zh2Bf7IKS82auT89 4tNgB4vnS92LOGUAcEsCY+Idnu32vr336tODo/LknvGOGYBvtHLoTqH3HWaOcSL4/W+Y Q+Xrr+Ut4rtN0OEpHOQO01B/+3pGd+Ea9uwi90XJC4B8M1rLH8Y84C5XM6azBvUnbzbV NB5w== 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=/74ZOEVtWoI92Rhuv9NWA62JHOdD9/euQUb+Sj4+JZg=; b=MOhs38O//AeCM+oZzqMGvwtyEhg7+NrVeWoJoi3Do83A6Y4WtOCXmxySHLCcYjb+k3 TSGgPF0BM37AUPaVZBsHvRXjRRQwLZolHJCt6fBn2VVdDyLMGHXV2/XN77eHssU8k+X+ Tk2+rKmL7/jz85ieYo/SpwYx+V8/d+4L4Aus4yKTNPHieERTO+MjJr250+on3LeudPEx eqfxCBbzPAZyg46GHr0k2e2vcOMuT4vSVyrMaDSW/G6X2PtQg7pw2dJBed5x/D9mNP9m O9P3jkqFaSqPakEPZQLaSMcbsG35Dx9E0b30g6hLZvktDC8PT4+6vPgLELaUP5vG0Zc+ oIsg== X-Gm-Message-State: AOAM533ngooLykBgIBsC9sCcHx8lRu1YaM97Casva4Iq9W1BamjXwOY1 Oprh8y6Tm8u59LvEdX5jJ47si8jzmxk= X-Google-Smtp-Source: ABdhPJwmVWhsHgXMGS5UDv329YVKJlrZm5l0XYS5jrAFMnCZIJaBqp9mxejIJt6y33aYA1cAzbYKoQ== X-Received: by 2002:aa7:c442:: with SMTP id n2mr13672084edr.309.1593524368446; Tue, 30 Jun 2020 06:39:28 -0700 (PDT) Received: from x1w.redhat.com (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id p18sm2099172ejm.55.2020.06.30.06.39.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 06:39:27 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v7 13/17] hw/sd/sdcard: Constify sd_crc*()'s message argument Date: Tue, 30 Jun 2020 15:39:07 +0200 Message-Id: <20200630133912.9428-14-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200630133912.9428-1-f4bug@amsat.org> References: <20200630133912.9428-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::544; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ed1-x544.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Alistair Francis , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" CRC functions don't modify the buffer argument, make it const. Reviewed-by: Alistair Francis Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 2946fe3040..364a6d1fcd 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -255,11 +255,11 @@ static const int sd_cmd_class[SDMMC_CMD_MAX] = { 7, 7, 10, 7, 9, 9, 9, 8, 8, 10, 8, 8, 8, 8, 8, 8, }; -static uint8_t sd_crc7(void *message, size_t width) +static uint8_t sd_crc7(const void *message, size_t width) { int i, bit; uint8_t shift_reg = 0x00; - uint8_t *msg = (uint8_t *) message; + const uint8_t *msg = (const uint8_t *)message; for (i = 0; i < width; i ++, msg ++) for (bit = 7; bit >= 0; bit --) { @@ -271,11 +271,11 @@ static uint8_t sd_crc7(void *message, size_t width) return shift_reg; } -static uint16_t sd_crc16(void *message, size_t width) +static uint16_t sd_crc16(const void *message, size_t width) { int i, bit; uint16_t shift_reg = 0x0000; - uint16_t *msg = (uint16_t *) message; + const uint16_t *msg = (const uint16_t *)message; width <<= 1; for (i = 0; i < width; i ++, msg ++) From patchwork Tue Jun 30 13:39:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 279019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9794C433DF for ; Tue, 30 Jun 2020 13:52:33 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 79539206BE for ; Tue, 30 Jun 2020 13:52:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b0iPdTLa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 79539206BE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46100 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqGga-0006l5-Nu for qemu-devel@archiver.kernel.org; Tue, 30 Jun 2020 09:52:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqGU0-0001L0-V1; Tue, 30 Jun 2020 09:39:33 -0400 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]:40666) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jqGTz-0006LD-I0; Tue, 30 Jun 2020 09:39:32 -0400 Received: by mail-ed1-x52b.google.com with SMTP id b15so16234309edy.7; Tue, 30 Jun 2020 06:39:30 -0700 (PDT) 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=8lBaOHF/GcJdlX2f+JY4g5jrg7UGtZKo4oX0j/i7PeY=; b=b0iPdTLafCOIL2wYrpU8x/TiYe8AO2FfoQ0xZsbIN7arJ+enWM0QSBBYES+MGeDYMn 4jFiYrXWMH7XblPyxgw5xd+etUZOWpX70rPPLo6eyvigubgsrogySa5AWIfgPZlwYjYf VJJ+e7/gaLkHLAW+U4x4IsMTOfnKM4fJyRPMEgX+FrNWtUhiUUQG20gpW4QEmiGAXwJ/ UxLRkkav34edDP8ysM5HUV8MbM8k6zl4pmcXRYQUZ59QNQ/vbK2MkWsRpUlg1sFo16IG 3m9E8Y0Z/9F3nL9/3j+1rbeOX7rDOXAxbF5BpSD4bPREDpYHBTLoemR8wh3vkWGPbAuA Osug== 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=8lBaOHF/GcJdlX2f+JY4g5jrg7UGtZKo4oX0j/i7PeY=; b=PPRSq6lytkRzb2SBtJxshhBn0D0xm3dROOTUetA1Sq4jQPhouZQfejQ5/S1lca77VV PnapJcfyGYLl8NI5kjWHpXpi2fZYDS6qO3gUN+c6Vwql6QPIlXbeHiW2CMN8wR8xSffT 8PqffXeOEbyWdoRZUFo79beNws25E3AIxLsMxS3fWPJ9nJASE6bt74lf2D7X2OE9+GSI imh9Fxj9p2epQjRHwzhJ+RCATPH3CldQdBAorGz+8MUa0w3M/nP6VloO+LUJB328yiIq 8w3WfI/wJtuMT/KPq/I5TDa/MmVsdxxC3EaEy9ViFZbf3lUIkscQWsdWdC4eNx26OIEq TNkA== X-Gm-Message-State: AOAM532dQ6rREwRCCaBuSzirZolrq9HBcAY866rIVtr6GRVnQLNh8F8j i7GxfXSvSwQCG8Pa4rk3b45M9sXI/w0= X-Google-Smtp-Source: ABdhPJwCxYkNof7NMTt+GqTjBdGAwrEJ2kqlkkf2HuxMgPVhtIUfPtoiItGXWTS/lZZHy5E7skaJmA== X-Received: by 2002:a05:6402:b79:: with SMTP id cb25mr3624013edb.154.1593524369661; Tue, 30 Jun 2020 06:39:29 -0700 (PDT) Received: from x1w.redhat.com (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id p18sm2099172ejm.55.2020.06.30.06.39.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 06:39:29 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v7 14/17] hw/sd/sdcard: Make iolen unsigned Date: Tue, 30 Jun 2020 15:39:08 +0200 Message-Id: <20200630133912.9428-15-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200630133912.9428-1-f4bug@amsat.org> References: <20200630133912.9428-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52b; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ed1-x52b.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?b?YXVkw6k=?= , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Philippe Mathieu-Daudé I/O request length can not be negative. Signed-off-by: Philippe Mathieu-Daudé --- v4: Use uint32_t (pm215) --- hw/sd/sd.c | 2 +- hw/sd/trace-events | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 364a6d1fcd..3e9faa8add 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -1981,7 +1981,7 @@ uint8_t sd_read_data(SDState *sd) { /* TODO: Append CRCs */ uint8_t ret; - int io_len; + uint32_t io_len; if (!sd->blk || !blk_is_inserted(sd->blk) || !sd->enable) return 0x00; diff --git a/hw/sd/trace-events b/hw/sd/trace-events index 5f09d32eb2..d0cd7c6ec4 100644 --- a/hw/sd/trace-events +++ b/hw/sd/trace-events @@ -52,7 +52,7 @@ sdcard_unlock(void) "" sdcard_read_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" sdcard_write_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" sdcard_write_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint8_t value) "%s %20s/ CMD%02d value 0x%02x" -sdcard_read_data(const char *proto, const char *cmd_desc, uint8_t cmd, int length) "%s %20s/ CMD%02d len %d" +sdcard_read_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint32_t length) "%s %20s/ CMD%02d len %" PRIu32 sdcard_set_voltage(uint16_t millivolts) "%u mV" # milkymist-memcard.c